add a healthy 1 sec delay between JEI transfer updates to avoid horrible
GC pressure
This commit is contained in:
@@ -266,7 +266,7 @@ public class DualityFluidInterface implements IGridTickable, IStorageMonitorable
|
||||
final Block directedBlock = directedBlockState.getBlock();
|
||||
ItemStack what = new ItemStack(directedBlock, 1, directedBlock.getMetaFromState(directedBlockState));
|
||||
|
||||
if (Loader.isModLoaded("gregtech") && directedBlock instanceof BlockMachine) {
|
||||
if (Platform.GTLoaded && directedBlock instanceof BlockMachine) {
|
||||
MetaTileEntity metaTileEntity = Platform.getMetaTileEntity(directedTile.getWorld(), directedTile.getPos());
|
||||
if (metaTileEntity != null) {
|
||||
return metaTileEntity.getMetaFullName();
|
||||
|
||||
@@ -1105,7 +1105,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
|
||||
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor(te, s.getOpposite());
|
||||
if (ad != null) {
|
||||
if (Loader.isModLoaded("actuallyadditions") && Loader.isModLoaded("gregtech") && te instanceof IPhantomTile) {
|
||||
if (Loader.isModLoaded("actuallyadditions") && Platform.GTLoaded && te instanceof IPhantomTile) {
|
||||
IPhantomTile phantomTE = ((IPhantomTile) te);
|
||||
if (phantomTE.hasBoundPosition()) {
|
||||
TileEntity phantom = w.getTileEntity(phantomTE.getBoundPosition());
|
||||
@@ -1287,7 +1287,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
final Block directedBlock = directedBlockState.getBlock();
|
||||
ItemStack what = new ItemStack(directedBlock, 1, directedBlock.getMetaFromState(directedBlockState));
|
||||
|
||||
if (Loader.isModLoaded("gregtech") && directedBlock instanceof BlockMachine) {
|
||||
if (Platform.GTLoaded && directedBlock instanceof BlockMachine) {
|
||||
MetaTileEntity metaTileEntity = Platform.getMetaTileEntity(directedTile.getWorld(), directedTile.getPos());
|
||||
if (metaTileEntity != null) {
|
||||
return metaTileEntity.getMetaFullName();
|
||||
|
||||
@@ -42,7 +42,7 @@ public class NonBlockingItems {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ModItemMeta[0].equals("gregtech") && Platform.isModLoaded("gregtech")) {
|
||||
if (ModItemMeta[0].equals("gregtech") && Platform.GTLoaded) {
|
||||
boolean found = false;
|
||||
for (MetaItem<?> metaItem : MetaItem.getMetaItems()) {
|
||||
MetaItem<?>.MetaValueItem metaItem2 = metaItem.getItem(ModItemMeta[1]);
|
||||
|
||||
@@ -14,7 +14,6 @@ import mezz.jei.api.gui.IRecipeLayout;
|
||||
import mezz.jei.api.recipe.transfer.IRecipeTransferError;
|
||||
import mezz.jei.gui.recipes.RecipeLayout;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
@@ -25,13 +24,19 @@ import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static mezz.jei.api.recipe.transfer.IRecipeTransferError.Type.USER_FACING;
|
||||
|
||||
public class JEIMissingItem implements IRecipeTransferError {
|
||||
|
||||
private boolean errored;
|
||||
public long lastUpdate;
|
||||
private final List<Integer> craftableSlots = new ArrayList<>();
|
||||
private final List<Integer> foundSlots = new ArrayList<>();
|
||||
|
||||
IItemList<IAEItemStack> available = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
|
||||
IItemList<IAEItemStack> used = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
|
||||
JEIMissingItem(Container container, @Nonnull IRecipeLayout recipeLayout) {
|
||||
if (container instanceof ContainerCraftingTerm) {
|
||||
@@ -110,31 +115,47 @@ public class JEIMissingItem implements IRecipeTransferError {
|
||||
int currentSlot = 0;
|
||||
this.errored = false;
|
||||
|
||||
IItemList<IAEItemStack> available = mergeInventories(ir, (ContainerCraftingTerm) minecraft.player.openContainer);
|
||||
|
||||
IItemList<IAEItemStack> used = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
if (System.currentTimeMillis() - lastUpdate > 1000) {
|
||||
lastUpdate = System.currentTimeMillis();
|
||||
available = mergeInventories(ir, (ContainerCraftingTerm) minecraft.player.openContainer);
|
||||
this.foundSlots.clear();
|
||||
this.craftableSlots.clear();
|
||||
} else {
|
||||
for (IGuiIngredient<?> i : recipeLayout.getItemStacks().getGuiIngredients().values()) {
|
||||
if (i.isInput()) {
|
||||
if (!foundSlots.contains(currentSlot)) {
|
||||
if (craftableSlots.contains(currentSlot)) {
|
||||
i.drawHighlight(minecraft, new Color(0.0f, 0.0f, 1.0f, 0.4f), recipeX, recipeY);
|
||||
} else {
|
||||
i.drawHighlight(minecraft, new Color(1.0f, 0.0f, 0.0f, 0.4f), recipeX, recipeY);
|
||||
}
|
||||
}
|
||||
}
|
||||
currentSlot++;
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.used.resetStatus();
|
||||
|
||||
for (IGuiIngredient<?> i : recipeLayout.getItemStacks().getGuiIngredients().values()) {
|
||||
found = false;
|
||||
craftable = false;
|
||||
List<ItemStack> valid = new ArrayList<>();
|
||||
if (i.isInput() && i.getAllIngredients().size() > 0) {
|
||||
ArrayList<ItemStack> valid = new ArrayList<>();
|
||||
if (i.isInput()) {
|
||||
List<?> allIngredients = i.getAllIngredients();
|
||||
for (Object allIngredient : allIngredients) {
|
||||
if (allIngredient instanceof ItemStack) {
|
||||
ItemStack stack = (ItemStack) allIngredient;
|
||||
if (!stack.isEmpty()) {
|
||||
IAEItemStack search = AEItemStack.fromItemStack(stack);
|
||||
if (stack.getItem().isDamageable() || Platform.isGTDamageableItem(stack.getItem())) {
|
||||
Collection<IAEItemStack> fuzzy = available.findFuzzy(AEItemStack.fromItemStack(stack), FuzzyMode.IGNORE_ALL);
|
||||
Collection<IAEItemStack> fuzzy = available.findFuzzy(search, FuzzyMode.IGNORE_ALL);
|
||||
if (fuzzy.size() > 0) {
|
||||
for (IAEItemStack itemStack : fuzzy) {
|
||||
if (itemStack.getStackSize() > 0) {
|
||||
if (itemStack.fuzzyComparison(AEItemStack.fromItemStack(stack), FuzzyMode.IGNORE_ALL)) {
|
||||
found = true;
|
||||
used.add(itemStack.copy().setStackSize(1));
|
||||
valid.addAll(fuzzy.stream().map(IAEItemStack::createItemStack).collect(Collectors.toList()));
|
||||
break;
|
||||
}
|
||||
found = true;
|
||||
used.add(itemStack.copy().setStackSize(1));
|
||||
valid.add(itemStack.copy().setStackSize(1).createItemStack());
|
||||
} else {
|
||||
if (itemStack.isCraftable()) {
|
||||
craftable = true;
|
||||
@@ -143,7 +164,7 @@ public class JEIMissingItem implements IRecipeTransferError {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
IAEItemStack ext = available.findPrecise(AEItemStack.fromItemStack(stack));
|
||||
IAEItemStack ext = available.findPrecise(search);
|
||||
if (ext != null) {
|
||||
IAEItemStack usedStack = used.findPrecise(ext);
|
||||
if (ext.getStackSize() > 0 && (usedStack == null || usedStack.getStackSize() < ext.getStackSize())) {
|
||||
@@ -159,20 +180,26 @@ public class JEIMissingItem implements IRecipeTransferError {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i.getAllIngredients().size() == 0) {
|
||||
found = true;
|
||||
}
|
||||
if (!found) {
|
||||
if (craftable) {
|
||||
i.drawHighlight(minecraft, new Color(0.0f, 0.0f, 1.0f, 0.4f), recipeX, recipeY);
|
||||
this.craftableSlots.add(currentSlot);
|
||||
recipeLayout.getItemStacks().set(currentSlot, valid);
|
||||
} else {
|
||||
i.drawHighlight(minecraft, new Color(1.0f, 0.0f, 0.0f, 0.4f), recipeX, recipeY);
|
||||
}
|
||||
this.errored = true;
|
||||
} else {
|
||||
this.foundSlots.add(currentSlot);
|
||||
recipeLayout.getItemStacks().set(currentSlot, valid);
|
||||
this.errored = false;
|
||||
}
|
||||
}
|
||||
currentSlot++;
|
||||
@@ -183,10 +210,6 @@ public class JEIMissingItem implements IRecipeTransferError {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean errored() {
|
||||
return this.errored;
|
||||
}
|
||||
|
||||
IItemList<IAEItemStack> mergeInventories(IItemList<IAEItemStack> repo, ContainerCraftingTerm containerCraftingTerm) {
|
||||
IItemList<IAEItemStack> itemList = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
for (IAEItemStack i : repo) {
|
||||
@@ -204,4 +227,8 @@ public class JEIMissingItem implements IRecipeTransferError {
|
||||
}
|
||||
return itemList;
|
||||
}
|
||||
|
||||
public boolean errored() {
|
||||
return errored;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,6 +146,7 @@ public class Platform {
|
||||
private static final ItemComparisonHelper ITEM_COMPARISON_HELPER = new ItemComparisonHelper();
|
||||
private static final P2PHelper P2P_HELPER = new P2PHelper();
|
||||
private static Method reflectGTgetMTE;
|
||||
public static final boolean GTLoaded = isModLoaded("gregtech");
|
||||
|
||||
public static ItemComparisonHelper itemComparisons() {
|
||||
return ITEM_COMPARISON_HELPER;
|
||||
@@ -1416,7 +1417,7 @@ public class Platform {
|
||||
|
||||
//consider methods below moving to a compability class
|
||||
public static boolean isGTDamageableItem(Item item) {
|
||||
return (isModLoaded("gregtech") && item instanceof IToolItem);
|
||||
return ((GTLoaded) && item instanceof IToolItem);
|
||||
}
|
||||
|
||||
public static MetaTileEntity getMetaTileEntity(IBlockAccess world, BlockPos pos) {
|
||||
|
||||
Reference in New Issue
Block a user