mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-28 16:06:48 +01:00
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:
parent
bf1c86ed87
commit
06ca8b0d1c
3 changed files with 71 additions and 13 deletions
|
@ -22,6 +22,8 @@ public class BlueprintTransferHandler implements IRecipeTransferHandler<Blueprin
|
||||||
PlayerEntity player, boolean maxTransfer, boolean doTransfer) {
|
PlayerEntity player, boolean maxTransfer, boolean doTransfer) {
|
||||||
if (!(recipe instanceof IRecipe))
|
if (!(recipe instanceof IRecipe))
|
||||||
return null;
|
return null;
|
||||||
|
if (!doTransfer)
|
||||||
|
return null;
|
||||||
IRecipe<?> iRecipe = (IRecipe<?>) recipe;
|
IRecipe<?> iRecipe = (IRecipe<?>) recipe;
|
||||||
// Continued server-side in BlueprintItem.assignCompleteRecipe()
|
// Continued server-side in BlueprintItem.assignCompleteRecipe()
|
||||||
AllPackets.channel.sendToServer(new BlueprintAssignCompleteRecipePacket(iRecipe.getId()));
|
AllPackets.channel.sendToServer(new BlueprintAssignCompleteRecipePacket(iRecipe.getId()));
|
||||||
|
|
|
@ -2,15 +2,19 @@ package com.simibubi.create.content.curiosities.tools;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.IdentityHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
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.BlueprintCraftingInventory;
|
||||||
import com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintSection;
|
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.FilterItem;
|
||||||
|
import com.simibubi.create.content.logistics.item.filter.ItemAttribute;
|
||||||
import com.simibubi.create.foundation.gui.AllGuiTextures;
|
import com.simibubi.create.foundation.gui.AllGuiTextures;
|
||||||
import com.simibubi.create.foundation.gui.GuiGameElement;
|
import com.simibubi.create.foundation.gui.GuiGameElement;
|
||||||
import com.simibubi.create.foundation.utility.AnimationTickHolder;
|
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.Minecraft;
|
||||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||||
import net.minecraft.inventory.CraftingInventory;
|
import net.minecraft.inventory.CraftingInventory;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
import net.minecraft.item.crafting.ICraftingRecipe;
|
import net.minecraft.item.crafting.ICraftingRecipe;
|
||||||
import net.minecraft.item.crafting.IRecipeType;
|
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.EntityRayTraceResult;
|
||||||
import net.minecraft.util.math.RayTraceResult;
|
import net.minecraft.util.math.RayTraceResult;
|
||||||
import net.minecraft.util.math.RayTraceResult.Type;
|
import net.minecraft.util.math.RayTraceResult.Type;
|
||||||
import net.minecraft.util.text.TextFormatting;
|
import net.minecraft.util.text.TextFormatting;
|
||||||
|
import net.minecraftforge.common.util.Constants.NBT;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
import net.minecraftforge.items.ItemStackHandler;
|
import net.minecraftforge.items.ItemStackHandler;
|
||||||
|
|
||||||
|
@ -37,6 +48,7 @@ public class BlueprintOverlayRenderer {
|
||||||
static boolean lastSneakState;
|
static boolean lastSneakState;
|
||||||
static BlueprintSection lastTargetedSection;
|
static BlueprintSection lastTargetedSection;
|
||||||
|
|
||||||
|
static Map<ItemStack, ItemStack[]> cachedRenderedFilters = new IdentityHashMap<>();
|
||||||
static List<Pair<ItemStack, Boolean>> ingredients = new ArrayList<>();
|
static List<Pair<ItemStack, Boolean>> ingredients = new ArrayList<>();
|
||||||
static ItemStack result = ItemStack.EMPTY;
|
static ItemStack result = ItemStack.EMPTY;
|
||||||
static boolean resultCraftable = false;
|
static boolean resultCraftable = false;
|
||||||
|
@ -72,6 +84,7 @@ public class BlueprintOverlayRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void rebuild(BlueprintSection sectionAt, boolean sneak) {
|
public static void rebuild(BlueprintSection sectionAt, boolean sneak) {
|
||||||
|
cachedRenderedFilters.clear();
|
||||||
ItemStackHandler items = sectionAt.getItems();
|
ItemStackHandler items = sectionAt.getItems();
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
for (int i = 0; i < 9; i++) {
|
for (int i = 0; i < 9; i++) {
|
||||||
|
@ -206,13 +219,9 @@ public class BlueprintOverlayRenderer {
|
||||||
RenderSystem.enableBlend();
|
RenderSystem.enableBlend();
|
||||||
(pair.getSecond() ? AllGuiTextures.HOTSLOT_ACTIVE : AllGuiTextures.HOTSLOT).draw(ms, x, y);
|
(pair.getSecond() ? AllGuiTextures.HOTSLOT_ACTIVE : AllGuiTextures.HOTSLOT).draw(ms, x, y);
|
||||||
ItemStack itemStack = pair.getFirst();
|
ItemStack itemStack = pair.getFirst();
|
||||||
GuiGameElement.of(itemStack)
|
String count = pair.getSecond() || itemStack.getCount() == 1 ? null
|
||||||
.at(x + 3, y + 3)
|
: TextFormatting.GOLD.toString() + itemStack.getCount();
|
||||||
.render(ms);
|
drawItemStack(ms, mc, x, y, itemStack, count);
|
||||||
mc.getItemRenderer()
|
|
||||||
.renderItemOverlayIntoGUI(mc.fontRenderer, itemStack, x + 3, y + 3,
|
|
||||||
pair.getSecond() || itemStack.getCount() == 1 ? null
|
|
||||||
: TextFormatting.GOLD.toString() + itemStack.getCount());
|
|
||||||
x += 21;
|
x += 21;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,12 +238,59 @@ public class BlueprintOverlayRenderer {
|
||||||
} else {
|
} else {
|
||||||
(resultCraftable ? AllGuiTextures.HOTSLOT_SUPER_ACTIVE : AllGuiTextures.HOTSLOT).draw(ms,
|
(resultCraftable ? AllGuiTextures.HOTSLOT_SUPER_ACTIVE : AllGuiTextures.HOTSLOT).draw(ms,
|
||||||
resultCraftable ? x - 1 : x, resultCraftable ? y - 1 : y);
|
resultCraftable ? x - 1 : x, resultCraftable ? y - 1 : y);
|
||||||
GuiGameElement.of(result)
|
drawItemStack(ms, mc, x, y, result, null);
|
||||||
.at(x + 3, y + 3)
|
|
||||||
.render(ms);
|
|
||||||
mc.getItemRenderer()
|
|
||||||
.renderItemOverlayIntoGUI(mc.fontRenderer, result, x + 3, y + 3, 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];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,7 @@ public interface ItemAttribute {
|
||||||
|
|
||||||
public static class InTag implements ItemAttribute {
|
public static class InTag implements ItemAttribute {
|
||||||
|
|
||||||
ResourceLocation tagName;
|
public ResourceLocation tagName;
|
||||||
|
|
||||||
public InTag(ResourceLocation tagName) {
|
public InTag(ResourceLocation tagName) {
|
||||||
this.tagName = tagName;
|
this.tagName = tagName;
|
||||||
|
|
Loading…
Reference in a new issue