Compare commits
66 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6f42876963 | |||
| 08952b48dd | |||
| e3c9c4ce65 | |||
| 7b91da58c0 | |||
| 26c06bca15 | |||
| 4458bd28ab | |||
| df3f00d978 | |||
| 18ae994ee4 | |||
| 47888b5546 | |||
| 9b9579b358 | |||
| 52da4f9528 | |||
| 50aac2c768 | |||
| 33946438bd | |||
| 9372cb2f14 | |||
| 00037ace77 | |||
| e13af643ba | |||
| ffcfd809d8 | |||
| 7c10a6b883 | |||
| c2bddc30c4 | |||
| 024655f84d | |||
| 589e48ac01 | |||
| 43d3a2c1c0 | |||
| c432fa7200 | |||
| cc744ab8b9 | |||
| 8fe4229a8e | |||
| 3f86884965 | |||
| 1319ec79c9 | |||
| 31a3afc18b | |||
| 9d6026635d | |||
| 39038ac935 | |||
| 4f627b234c | |||
| 6180c188e6 | |||
| 7ada6d18ee | |||
| f493767243 | |||
| ba4cdbcb85 | |||
| f3877aa1ec | |||
| 366b31b3aa | |||
| 533fb5c34b | |||
| 62d1d904c6 | |||
| 03fb43db16 | |||
| 9576bec855 | |||
| b5da6730a1 | |||
| 039bab4811 | |||
| 4b5bdf9893 | |||
| 3c3c23712d | |||
| af91c04ea1 | |||
| 0240a5d76a | |||
| 0c0aafba2f | |||
| b541025738 | |||
| 62f842d4ef | |||
| fc154d8568 | |||
| 4641e48529 | |||
| 0fae87afc7 | |||
| ee1b6bb0d7 | |||
| 36ca8b9f0a | |||
| 9c94c7342b | |||
| 399d67b42c | |||
| 10761a1e9d | |||
| d1ddf53d99 | |||
| f776b4d548 | |||
| 41180792e1 | |||
| 2269c05d98 | |||
| 63616e5730 | |||
| 6ca3e6e696 | |||
| a4b5cfc3b9 | |||
| 38b0a7a153 |
+47
@@ -0,0 +1,47 @@
|
||||
Changes so far :
|
||||
|
||||
Design changes/breakages:
|
||||
- Interfaces no longer spill items of one pattern on other faces
|
||||
- Interfaces now push patterns in round-robin (Interfaces, then sides)
|
||||
|
||||
|
||||
|
||||
|
||||
Fixes:
|
||||
|
||||
- Fix gregtech machines appearing with 'unnamed' or 'draconium lens' on the interface terminal on specific situations.
|
||||
- Add memorycard support for fluid interfaces, import/export/storage busses and level emitters ( this fix was upstreamed to AE2 for MC 1.16)
|
||||
- Storage busses now hide/show inaccessible items as configured.
|
||||
- Exclusive Blocking mode for GTCE ( shapes, molds and configured circuits do not block GTCE machines )
|
||||
- Blocking modes default to block on any item in the iventory the entity exposes
|
||||
- Fuzzy includes items that report that they're damageable, but report a maxDamage of 0 ( auto-crafting of basic capacitors -> resonant capacitors is now possible ) <- Broken item implementation.
|
||||
|
||||
Performance:
|
||||
|
||||
- Added @talchas fixes for insane channelless AE networks.
|
||||
- Implemented StorageDrawers slotless itemrepository.
|
||||
- Removed CraftedEvent calls (really bad lag with craftweaker versions before CraftTweaker2-1.12-4.1.20.626)
|
||||
- Count items set in interfaces before queuing crafting for them needlessly
|
||||
- Backported b7ca98d ( Avoid copying items on simulated item extraction )
|
||||
- Cache some level emitters functions
|
||||
|
||||
QOL:
|
||||
|
||||
- added highlight interface button to interface terminal ("?" button on the left of the interface slots)
|
||||
- Added bar on the interface terminal that search by inputs ( The one on the LEFT, also searchs by interface name )
|
||||
- Shortcut to molecular assemblers with free slots on the terminal interface by @Theisyat
|
||||
- Toggle button on interface terminal to hide full interfaces
|
||||
- JEI "U""R" and "A" (Usages/Recipes/Bookmark) now work on the Crafting Status GUI. ( the one that shows the total items to craft, and whats missing)
|
||||
- Patterns can now be made with items currently showing on JEI. ( This is overriden by Just Enough Energistics. )
|
||||
- Added multiplier buttons to processing pattern gui
|
||||
- Switched crafting terminal JEI search to fuzzy mode. If the recipe uses a damageable item, AE will try to grab it ( damaged tools )
|
||||
- Encoded patterns stack up to 64 ( holding shift and clicking the encode arrow will transfer the encoded pattern to the player inventory)
|
||||
- Encoded patterns can be draggred on the interface terminal.
|
||||
- Storage Monitor and Conversion Monitor now also ccepts fluids
|
||||
- Draggable JEI ghost items (also works on bookmarked items. SHIFT + Click will move the hovered item into the first free target slot)
|
||||
-JEI auto switches between crafting and processing patterns
|
||||
|
||||
HOTKEYS:
|
||||
|
||||
- Implemented mousetweaks API. AE2 custom keybinds now work. (Try right clicking and use the scroll-wheel on the terminals)
|
||||
- Holding SHIFT and scrolling UP and DOWN will increase the items set on the configured slots of Interfaces and Pattern Terminal (Processing mode)
|
||||
@@ -19,11 +19,6 @@
|
||||
repositories {
|
||||
mavenLocal()
|
||||
|
||||
maven {
|
||||
name = "storagedrawers"
|
||||
url = "https://dl.bintray.com/jaquadro/dev/"
|
||||
}
|
||||
|
||||
maven {
|
||||
name "Mobius"
|
||||
url "http://mobiusstrip.eu/maven"
|
||||
@@ -39,6 +34,11 @@ repositories {
|
||||
url "http://maven.mcmoddev.com"
|
||||
}
|
||||
|
||||
maven {
|
||||
name "Ellpeck"
|
||||
url "https://maven.ellpeck.de"
|
||||
}
|
||||
|
||||
maven {
|
||||
name = "IC2 repo"
|
||||
url = "http://maven.ic2.player.to"
|
||||
@@ -59,11 +59,6 @@ repositories {
|
||||
url "http://maven.k-4u.nl/"
|
||||
}
|
||||
|
||||
maven { // Hwyla
|
||||
name 'tehnut'
|
||||
url "http://tehnut.info/maven"
|
||||
}
|
||||
|
||||
maven { // CraftTweaker
|
||||
name 'jared maven'
|
||||
url "http://maven.blamejared.com/"
|
||||
@@ -85,7 +80,6 @@ configurations {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly "com.jaquadro.minecraft.storagedrawers:StorageDrawers:1.12.2-5.4.2:api"
|
||||
compileOnly "gregtechce:gregtech:1.12.2:1.12.0.662"
|
||||
|
||||
// installable runtime dependencies
|
||||
@@ -103,11 +97,10 @@ dependencies {
|
||||
compileOnly "CraftTweaker2:CraftTweaker2-API:${crafttweaker_version}"
|
||||
compileOnly "inventory-tweaks:InventoryTweaks:${inventorytweaks_version}:api"
|
||||
compileOnly "team.chisel.ctm:CTM:${ctm_version}"
|
||||
compileOnly "de.ellpeck.actuallyadditions:ActuallyAdditions:1.12.2-r152.16:api"
|
||||
|
||||
// at runtime, use the full JEI jar
|
||||
runtime "mezz.jei:jei_${minecraft_version}:${jei_version}"
|
||||
runtime "com.jaquadro.minecraft.storagedrawers:StorageDrawers:1.12.2-5.4.2"
|
||||
runtime "com.jaquadro.minecraft.chameleon:Chameleon:1.12-4.1.3"
|
||||
|
||||
// unit test dependencies
|
||||
testCompile "junit:junit:4.12"
|
||||
|
||||
@@ -112,4 +112,13 @@ public interface IAEItemStack extends IAEStack<IAEItemStack>
|
||||
* @return definition stack
|
||||
*/
|
||||
ItemStack getDefinition();
|
||||
|
||||
/**
|
||||
* Compare this AE item stack to another item stack, but ignores
|
||||
* the amount. It checks the item type, NBT and damage values.
|
||||
*
|
||||
* @param is An item stack
|
||||
*/
|
||||
boolean equals(ItemStack is);
|
||||
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
package com.jaquadro.minecraft.storagedrawers.api.capabilities;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* An interface for treating an inventory as a slotless, central repository of items.
|
||||
*
|
||||
* For all operations that accept a predicate, if a predicate is supplied, a stored ItemStack must pass the predicate
|
||||
* in order to be considered for the given operation.
|
||||
*
|
||||
* An IItemRepository implementation MAY relax or eliminate its own internal tests when a predicate is supplied. If
|
||||
* the predicate is derived from DefaultPredicate, then the implementation MUST apply any tests it would have applied
|
||||
* had no predicate been provided at all, in addition to testing the predicate itself.
|
||||
*/
|
||||
public interface IItemRepository
|
||||
{
|
||||
/**
|
||||
* Gets a list of all items in the inventory. The same item may appear multiple times with varying counts.
|
||||
|
||||
* @return A list of zero or more items in the inventory.
|
||||
*/
|
||||
@Nonnull
|
||||
NonNullList<ItemRecord> getAllItems ();
|
||||
|
||||
/**
|
||||
* Inserts an ItemStack into the inventory and returns the remainder.
|
||||
*
|
||||
* @param stack ItemStack to insert.
|
||||
* @param simulate If true, the insertion is only simulated
|
||||
* @param predicate See interface notes about predicates. Passing null specifies default matching.
|
||||
* @return The remaining ItemStack that was not inserted. If the entire stack was accepted, returns
|
||||
* ItemStack.EMPTY instead.
|
||||
*/
|
||||
@Nonnull
|
||||
ItemStack insertItem (@Nonnull ItemStack stack, boolean simulate, Predicate<ItemStack> predicate);
|
||||
|
||||
@Nonnull
|
||||
default ItemStack insertItem (@Nonnull ItemStack stack, boolean simulate) {
|
||||
return insertItem(stack, simulate, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to extract the given ItemStack from the inventory. The returned value will be a matching ItemStack
|
||||
* with a stack size equal to or less than amount, or the empty ItemStack if the item could not be found at all.
|
||||
* The returned stack size may exceed the ItemStack's getMaxStackSize() value.
|
||||
|
||||
* @param stack The item to extract. The stack size is ignored.
|
||||
* @param amount Amount to extract (may be greater than the stacks max limit)
|
||||
* @param simulate If true, the extraction is only simulated
|
||||
* @param predicate See interface notes about predicates. Passing null specifies default matching.
|
||||
* @return ItemStack extracted from the inventory, or ItemStack.EMPTY if nothing could be extracted.
|
||||
*/
|
||||
@Nonnull
|
||||
ItemStack extractItem (@Nonnull ItemStack stack, int amount, boolean simulate, Predicate<ItemStack> predicate);
|
||||
|
||||
@Nonnull
|
||||
default ItemStack extractItem (@Nonnull ItemStack stack, int amount, boolean simulate) {
|
||||
return extractItem(stack, amount, simulate, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of items matching the given ItemStack stored by the inventory.
|
||||
|
||||
* @param stack ItemStack to query.
|
||||
* @param predicate See interface notes about predicates. Passing null specifies default matching.
|
||||
* @return The number of stored matching items. A value of Integer.MAX_VALUE may indicate an infinite item source.
|
||||
*/
|
||||
default int getStoredItemCount (@Nonnull ItemStack stack, Predicate<ItemStack> predicate) {
|
||||
ItemStack amount = extractItem(stack, Integer.MAX_VALUE, true, predicate);
|
||||
return amount.getCount();
|
||||
}
|
||||
|
||||
default int getStoredItemCount (@Nonnull ItemStack stack) {
|
||||
return getStoredItemCount(stack, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number items matching the given ItemStack that additionally still be stored by the inventory.
|
||||
* Remaining capacity may include space that is internally empty or unassigned to any given item.
|
||||
*
|
||||
* @param stack ItemStack to query.
|
||||
* @param predicate See interface notes about predicates. Passing null specifies default matching.
|
||||
* @return The available remaining space for matching items.
|
||||
*/
|
||||
default int getRemainingItemCapacity (@Nonnull ItemStack stack, Predicate<ItemStack> predicate) {
|
||||
stack = stack.copy();
|
||||
stack.setCount(Integer.MAX_VALUE);
|
||||
ItemStack remainder = insertItem(stack, true, predicate);
|
||||
return Integer.MAX_VALUE - remainder.getCount();
|
||||
}
|
||||
|
||||
default int getRemainingItemCapacity (@Nonnull ItemStack stack) {
|
||||
return getRemainingItemCapacity(stack, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total inventory capacity for items matching the given ItemStack.
|
||||
* Total capacity may include space that is internally empty or unassigned to any given item.
|
||||
*
|
||||
* @param stack ItemStack to query.
|
||||
* @param predicate See interface notes about predicates. Passing null specifies default matching.
|
||||
* @return The total capacity for matching items.
|
||||
*/
|
||||
default int getItemCapacity (@Nonnull ItemStack stack, Predicate<ItemStack> predicate) {
|
||||
long capacity = getStoredItemCount(stack, predicate) + getRemainingItemCapacity(stack, predicate);
|
||||
if (capacity > Integer.MAX_VALUE)
|
||||
return Integer.MAX_VALUE;
|
||||
return (int)capacity;
|
||||
}
|
||||
|
||||
default int getItemCapacity (@Nonnull ItemStack stack) {
|
||||
return getItemCapacity(stack, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* An item record representing an item and the amount stored.
|
||||
*
|
||||
* The ItemStack held by itemPrototype always reports a stack size of 1.
|
||||
* IT IS IMPORTANT THAT YOU NEVER MODIFY itemPrototype.
|
||||
*/
|
||||
class ItemRecord
|
||||
{
|
||||
@Nonnull
|
||||
public final ItemStack itemPrototype;
|
||||
public final int count;
|
||||
|
||||
public ItemRecord (@Nonnull ItemStack itemPrototype, int count) {
|
||||
this.itemPrototype = itemPrototype;
|
||||
this.count = count;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A variant of the standard Predicate interface that when passed to IItemRepository functions, will ask the
|
||||
* internal default predicate to be tested in addition to the custom predicate. An IItemRepository function
|
||||
* may choose to enforce its own predicate regardless.
|
||||
*/
|
||||
interface DefaultPredicate<T> extends Predicate<T> { }
|
||||
}
|
||||
@@ -25,8 +25,11 @@ import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import appeng.client.gui.AEBaseGui;
|
||||
import appeng.container.interfaces.IJEIGhostIngredients;
|
||||
import appeng.helpers.HighlighterHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -36,10 +39,7 @@ import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.event.MouseEvent;
|
||||
import net.minecraftforge.client.event.RenderLivingEvent;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.client.event.*;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.common.ForgeModContainer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
@@ -75,6 +75,7 @@ import appeng.hooks.TickHandler;
|
||||
import appeng.hooks.TickHandler.PlayerColor;
|
||||
import appeng.server.ServerHelper;
|
||||
import appeng.util.Platform;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
|
||||
public class ClientHelper extends ServerHelper
|
||||
@@ -315,6 +316,28 @@ public class ClientHelper extends ServerHelper
|
||||
Minecraft.getMinecraft().effectRenderer.addEffect( fx );
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void MouseClickEvent( final GuiScreenEvent.MouseInputEvent.Pre me )
|
||||
{
|
||||
final Minecraft mc = Minecraft.getMinecraft();
|
||||
if( mc.currentScreen instanceof IJEIGhostIngredients )
|
||||
{
|
||||
AEBaseGui gui = ( (AEBaseGui) mc.currentScreen );
|
||||
Object ingredient = gui.getBookmarkedIngredient();
|
||||
if( ingredient != null )
|
||||
{
|
||||
if( GuiScreen.isShiftKeyDown() )
|
||||
{
|
||||
me.setCanceled( true );
|
||||
}
|
||||
else if( Mouse.isButtonDown( 0 ) )
|
||||
{
|
||||
me.setCanceled( true );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void wheelEvent( final MouseEvent me )
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package appeng.client.gui;
|
||||
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.ParseException;
|
||||
@@ -31,13 +32,16 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.container.slot.*;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import mezz.jei.api.gui.IGhostIngredientHandler;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
import net.minecraftforge.fml.common.Optional;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -71,17 +75,7 @@ import appeng.client.me.SlotDisconnected;
|
||||
import appeng.client.me.SlotME;
|
||||
import appeng.client.render.StackSizeRenderer;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.slot.AppEngCraftingSlot;
|
||||
import appeng.container.slot.AppEngSlot;
|
||||
import appeng.container.slot.AppEngSlot.hasCalculatedValidness;
|
||||
import appeng.container.slot.IOptionalSlot;
|
||||
import appeng.container.slot.SlotCraftingTerm;
|
||||
import appeng.container.slot.SlotDisabled;
|
||||
import appeng.container.slot.SlotFake;
|
||||
import appeng.container.slot.SlotInaccessible;
|
||||
import appeng.container.slot.SlotOutput;
|
||||
import appeng.container.slot.SlotPatternTerm;
|
||||
import appeng.container.slot.SlotRestrictedInput;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
@@ -92,6 +86,9 @@ import appeng.fluids.container.slots.IMEFluidSlot;
|
||||
import appeng.helpers.InventoryAction;
|
||||
import yalter.mousetweaks.api.IMTModGuiContainer2;
|
||||
|
||||
import static appeng.integration.modules.jei.JEIPlugin.aeGuiHandler;
|
||||
import static appeng.integration.modules.jei.JEIPlugin.runtime;
|
||||
|
||||
|
||||
@Optional.Interface( iface = "yalter.mousetweaks.api.IMTModGuiContainer2", modid = "mousetweaks" )
|
||||
public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContainer2
|
||||
@@ -106,6 +103,28 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
|
||||
private Stopwatch dbl_clickTimer = Stopwatch.createStarted();
|
||||
private ItemStack dbl_whichItem = ItemStack.EMPTY;
|
||||
private Slot bl_clicked;
|
||||
private Stopwatch lastClicked = Stopwatch.createStarted();
|
||||
private List<IGhostIngredientHandler.Target<Object>> hoveredIngredientTargets = new ArrayList<>();
|
||||
private Object bookmarkedIngredient;
|
||||
private boolean isDraggingJeiGhostItem;
|
||||
|
||||
public void setJeiGhostItem( boolean jeiGhostItem )
|
||||
{
|
||||
isJeiGhostItem = jeiGhostItem;
|
||||
}
|
||||
|
||||
private boolean isJeiGhostItem;
|
||||
|
||||
public Object getBookmarkedIngredient()
|
||||
{
|
||||
return bookmarkedIngredient;
|
||||
}
|
||||
|
||||
public List<GuiCustomSlot> getGuiSlots()
|
||||
{
|
||||
return guiSlots;
|
||||
}
|
||||
|
||||
protected final List<GuiCustomSlot> guiSlots = new ArrayList<>();
|
||||
|
||||
public AEBaseGui( final Container container )
|
||||
@@ -188,6 +207,65 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
|
||||
this.drawTooltip( (ITooltip) c, mouseX, mouseY );
|
||||
}
|
||||
}
|
||||
GlStateManager.enableDepth();
|
||||
bookmarkedJEIghostItem(mouseX,mouseY);
|
||||
GlStateManager.disableDepth();
|
||||
}
|
||||
|
||||
void bookmarkedJEIghostItem(final int mouseX, final int mouseY) {
|
||||
|
||||
if (!isJeiGhostItem)
|
||||
{
|
||||
bookmarkedIngredient = runtime.getBookmarkOverlay().getIngredientUnderMouse();
|
||||
}
|
||||
|
||||
if( bookmarkedIngredient != null )
|
||||
{
|
||||
hoveredIngredientTargets = aeGuiHandler.getTargets( this, bookmarkedIngredient, false );
|
||||
ItemStack dragItem = ItemStack.EMPTY;
|
||||
if( hoveredIngredientTargets.size() > 0 )
|
||||
{
|
||||
if( isShiftKeyDown() && Mouse.isButtonDown( 0 ) && this.lastClicked.elapsed( TimeUnit.MILLISECONDS ) > 200 )
|
||||
{
|
||||
this.lastClicked = Stopwatch.createStarted();
|
||||
aeGuiHandler.getTargets( this, bookmarkedIngredient, true );
|
||||
}
|
||||
else if( Mouse.isButtonDown( 0 ) && this.lastClicked.elapsed( TimeUnit.MILLISECONDS ) > 200 )
|
||||
{
|
||||
this.lastClicked = Stopwatch.createStarted();
|
||||
if( bookmarkedIngredient instanceof ItemStack )
|
||||
{
|
||||
dragItem = ( (ItemStack) bookmarkedIngredient );
|
||||
}
|
||||
else if( bookmarkedIngredient instanceof FluidStack )
|
||||
{
|
||||
dragItem = FluidUtil.getFilledBucket( ( (FluidStack) bookmarkedIngredient ) );
|
||||
}
|
||||
mc.player.inventory.setItemStack( dragItem.copy() );
|
||||
this.isJeiGhostItem = true;
|
||||
}
|
||||
drawTargets( mouseX, mouseY );
|
||||
}
|
||||
}
|
||||
}
|
||||
private void drawTargets(int mouseX, int mouseY) {
|
||||
GlStateManager.disableLighting();
|
||||
for( IGhostIngredientHandler.Target target : hoveredIngredientTargets )
|
||||
{
|
||||
Rectangle area = target.getArea();
|
||||
Color color;
|
||||
if( area.contains( mouseX, mouseY ) )
|
||||
{
|
||||
color = new Color( 76, 201, 25, 128 );
|
||||
}
|
||||
else
|
||||
{
|
||||
color = new Color( 19, 201, 10, 64 );
|
||||
}
|
||||
Gui.drawRect( area.x, area.y, area.x + area.width, area.y + area.height, color.getRGB() );
|
||||
}
|
||||
GlStateManager.color( 1f, 1f, 1f, 1f );
|
||||
GlStateManager.enableDepth();
|
||||
}
|
||||
|
||||
protected void drawGuiSlot( GuiCustomSlot slot, int mouseX, int mouseY, float partialTicks )
|
||||
@@ -320,7 +398,6 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
|
||||
{
|
||||
slot.drawBackground( ox, oy );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -387,29 +464,13 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
|
||||
{
|
||||
if( !itemstack.isEmpty() )
|
||||
{
|
||||
Set<IItemHandler> visitedInterfaces = new HashSet<>();
|
||||
for( final Slot dr : this.drag_click )
|
||||
{
|
||||
IItemHandler interfaceHandler = ( (SlotDisconnected) slot ).getSlot().getInventory();
|
||||
if (visitedInterfaces.contains( interfaceHandler )) break;
|
||||
visitedInterfaces.add( interfaceHandler );
|
||||
boolean canInsert = true;
|
||||
for( int s = 0; s < interfaceHandler.getSlots(); s++ )
|
||||
if( slot.getStack().isEmpty() )
|
||||
{
|
||||
if( ItemStack.areItemStacksEqual( interfaceHandler.getStackInSlot( s ), itemstack ) )
|
||||
{
|
||||
canInsert = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( canInsert )
|
||||
{
|
||||
if( slot.getStack().isEmpty() )
|
||||
{
|
||||
InventoryAction action = InventoryAction.SPLIT_OR_PLACE_SINGLE;
|
||||
final PacketInventoryAction p = new PacketInventoryAction( action, dr.getSlotIndex(), ( (SlotDisconnected) slot ).getSlot().getId() );
|
||||
NetworkHandler.instance().sendToServer( p );
|
||||
}
|
||||
InventoryAction action = InventoryAction.SPLIT_OR_PLACE_SINGLE;
|
||||
final PacketInventoryAction p = new PacketInventoryAction( action, dr.getSlotIndex(), ( (SlotDisconnected) slot ).getSlot().getId() );
|
||||
NetworkHandler.instance().sendToServer( p );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -445,18 +506,56 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
|
||||
{
|
||||
final EntityPlayer player = Minecraft.getMinecraft().player;
|
||||
|
||||
if( slot instanceof SlotFake )
|
||||
if( this.isJeiGhostItem && isDraggingJeiGhostItem)
|
||||
{
|
||||
final InventoryAction action = mouseButton == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN;
|
||||
for( IGhostIngredientHandler.Target target : hoveredIngredientTargets )
|
||||
{
|
||||
Rectangle area = target.getArea();
|
||||
final int x = Mouse.getEventX() * this.width / this.mc.displayWidth;
|
||||
final int y = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1;
|
||||
|
||||
if( area.contains( x, y ) )
|
||||
{
|
||||
target.accept( bookmarkedIngredient );
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.isJeiGhostItem = false;
|
||||
this.isDraggingJeiGhostItem = false;
|
||||
|
||||
ItemStack dragItem = ItemStack.EMPTY;
|
||||
if( runtime.getBookmarkOverlay().getIngredientUnderMouse() != null )
|
||||
{
|
||||
bookmarkedJEIghostItem( Mouse.getX(), this.mc.displayHeight - Mouse.getY() );
|
||||
if( bookmarkedIngredient instanceof ItemStack )
|
||||
{
|
||||
dragItem = ( (ItemStack) bookmarkedIngredient );
|
||||
}
|
||||
else if( bookmarkedIngredient instanceof FluidStack )
|
||||
{
|
||||
dragItem = FluidUtil.getFilledBucket( ( (FluidStack) bookmarkedIngredient ) );
|
||||
}
|
||||
mc.player.inventory.setItemStack( dragItem.copy() );
|
||||
this.isJeiGhostItem = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mc.player.inventory.setItemStack( dragItem );
|
||||
}
|
||||
}
|
||||
|
||||
else if( slot instanceof SlotFake )
|
||||
{
|
||||
final InventoryAction action;
|
||||
action = mouseButton == 1 ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN;
|
||||
|
||||
if( this.drag_click.size() > 1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final PacketInventoryAction p = new PacketInventoryAction( action, slotIdx, 0 );
|
||||
PacketInventoryAction p = new PacketInventoryAction( action, slotIdx, 0 );
|
||||
NetworkHandler.instance().sendToServer( p );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -538,23 +637,12 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
|
||||
case PICKUP: // pickup / set-down.
|
||||
if( slot.getStack().isEmpty() && !player.inventory.getItemStack().isEmpty() )
|
||||
{
|
||||
boolean canInsert = true;
|
||||
IItemHandler interfaceHandler = ( (SlotDisconnected) slot ).getSlot().getInventory();
|
||||
for( int s = 0; s < interfaceHandler.getSlots(); s++ )
|
||||
{
|
||||
if( ItemStack.areItemStacksEqual( interfaceHandler.getStackInSlot( s ), player.inventory.getItemStack() ) )
|
||||
{
|
||||
canInsert = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( canInsert )
|
||||
{
|
||||
action = InventoryAction.SPLIT_OR_PLACE_SINGLE;
|
||||
}
|
||||
break;
|
||||
action = InventoryAction.SPLIT_OR_PLACE_SINGLE;
|
||||
}
|
||||
if( !slot.getStack().isEmpty() && player.inventory.getItemStack().getCount() <= 1 )
|
||||
{
|
||||
action = InventoryAction.PICKUP_OR_SET_DOWN;
|
||||
}
|
||||
if( !slot.getStack().isEmpty() && player.inventory.getItemStack().getCount() <= 1 ) action = InventoryAction.PICKUP_OR_SET_DOWN;
|
||||
break;
|
||||
case QUICK_MOVE:
|
||||
action = ( mouseButton == 1 ) ? InventoryAction.PICKUP_SINGLE : InventoryAction.SHIFT_CLICK;
|
||||
@@ -587,14 +675,13 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
|
||||
InventoryAction action = null;
|
||||
IAEItemStack stack = null;
|
||||
|
||||
switch( clickType )
|
||||
switch ( clickType )
|
||||
{
|
||||
case PICKUP: // pickup / set-down.
|
||||
action = ( mouseButton == 1 ) ? InventoryAction.SPLIT_OR_PLACE_SINGLE : InventoryAction.PICKUP_OR_SET_DOWN;
|
||||
stack = ( (SlotME) slot ).getAEStack();
|
||||
|
||||
if( stack != null && action == InventoryAction.PICKUP_OR_SET_DOWN && stack.getStackSize() == 0 && player.inventory.getItemStack()
|
||||
.isEmpty() )
|
||||
if( stack != null && action == InventoryAction.PICKUP_OR_SET_DOWN && stack.getStackSize() == 0 && player.inventory.getItemStack().isEmpty() )
|
||||
{
|
||||
action = InventoryAction.AUTO_CRAFT;
|
||||
}
|
||||
@@ -661,9 +748,7 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
|
||||
final List<Slot> slots = this.getInventorySlots();
|
||||
for( final Slot inventorySlot : slots )
|
||||
{
|
||||
if( inventorySlot != null && inventorySlot.canTakeStack(
|
||||
this.mc.player ) && inventorySlot.getHasStack() && inventorySlot.isSameInventory( slot ) && Container.canAddItemToSlot(
|
||||
inventorySlot, this.dbl_whichItem, true ) )
|
||||
if( inventorySlot != null && inventorySlot.canTakeStack( this.mc.player ) && inventorySlot.getHasStack() && inventorySlot.isSameInventory( slot ) && Container.canAddItemToSlot( inventorySlot, this.dbl_whichItem, true ) )
|
||||
{
|
||||
this.handleMouseClick( inventorySlot, inventorySlot.slotNumber, 0, ClickType.QUICK_MOVE );
|
||||
}
|
||||
@@ -674,6 +759,11 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
|
||||
this.disableShiftClick = false;
|
||||
}
|
||||
|
||||
if (clickType == ClickType.PICKUP && isJeiGhostItem && !isDraggingJeiGhostItem) {
|
||||
this.isDraggingJeiGhostItem = true;
|
||||
return;
|
||||
}
|
||||
|
||||
super.handleMouseClick( slot, slotIdx, mouseButton, clickType );
|
||||
}
|
||||
|
||||
@@ -1101,4 +1191,5 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,26 +2,23 @@ package appeng.client.gui;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.client.gui.implementations.GuiCraftAmount;
|
||||
import appeng.client.gui.implementations.GuiCraftConfirm;
|
||||
import appeng.client.gui.implementations.GuiCraftingCPU;
|
||||
import appeng.client.gui.widgets.GuiCustomSlot;
|
||||
import appeng.container.implementations.ContainerCraftAmount;
|
||||
import appeng.client.gui.implementations.*;
|
||||
import appeng.container.interfaces.IJEIGhostIngredients;
|
||||
import appeng.container.slot.SlotFake;
|
||||
import appeng.fluids.client.gui.widgets.GuiFluidSlot;
|
||||
import mezz.jei.api.gui.IAdvancedGuiHandler;
|
||||
import net.minecraft.client.renderer.RenderItem;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import mezz.jei.api.gui.IGhostIngredientHandler;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class AEGuiHandler implements IAdvancedGuiHandler<AEBaseGui>
|
||||
public class AEGuiHandler implements IAdvancedGuiHandler<AEBaseGui>, IGhostIngredientHandler<AEBaseGui>
|
||||
{
|
||||
|
||||
@Override
|
||||
public Class<AEBaseGui> getGuiContainerClass()
|
||||
{
|
||||
@@ -39,8 +36,8 @@ public class AEGuiHandler implements IAdvancedGuiHandler<AEBaseGui>
|
||||
@Override
|
||||
public Object getIngredientUnderMouse( AEBaseGui guiContainer, int mouseX, int mouseY )
|
||||
{
|
||||
List<IAEItemStack> visual = new ArrayList<>();
|
||||
int guiSlotIdx = 0;
|
||||
List<IAEItemStack> visual;
|
||||
int guiSlotIdx;
|
||||
Object result = null;
|
||||
if( guiContainer instanceof GuiCraftConfirm )
|
||||
{
|
||||
@@ -94,4 +91,54 @@ public class AEGuiHandler implements IAdvancedGuiHandler<AEBaseGui>
|
||||
if( guiSloty > ( rows - 1 ) || mouseY < guitop + yo ) return -1;
|
||||
return ( guiSloty * 3 ) + guiSlotx + ( currentScroll * 3 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <I> List<Target<I>> getTargets( AEBaseGui gui, I ingredient, boolean doStart )
|
||||
{
|
||||
ArrayList<Target<I>> targets = new ArrayList<>();
|
||||
if( gui instanceof IJEIGhostIngredients )
|
||||
{
|
||||
IJEIGhostIngredients g = (IJEIGhostIngredients) gui;
|
||||
List<Target<?>> phantomTargets = g.getPhantomTargets( ingredient );
|
||||
targets.addAll( (List<Target<I>>) (Object) phantomTargets );
|
||||
}
|
||||
if( doStart && GuiScreen.isShiftKeyDown() && Mouse.isButtonDown( 0 ) )
|
||||
{
|
||||
if( gui instanceof GuiUpgradeable || gui instanceof GuiPatternTerm )
|
||||
{
|
||||
IJEIGhostIngredients ghostGui = ( (IJEIGhostIngredients) gui );
|
||||
for( Target<I> target : targets )
|
||||
{
|
||||
if( ghostGui.getFakeSlotTargetMap().get( target ) instanceof SlotFake )
|
||||
{
|
||||
if( ( (SlotFake) ghostGui.getFakeSlotTargetMap().get( target ) ).getStack().isEmpty() )
|
||||
{
|
||||
target.accept( ingredient );
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if( ghostGui.getFakeSlotTargetMap().get( target ) instanceof GuiFluidSlot )
|
||||
{
|
||||
if( ( (GuiFluidSlot) ghostGui.getFakeSlotTargetMap().get( target ) ).getFluidStack() == null )
|
||||
{
|
||||
target.accept( ingredient );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return targets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldHighlightTargets()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.*;
|
||||
import appeng.api.config.ActionItems;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.client.gui.widgets.GuiImgButton;
|
||||
import appeng.core.worlddata.IWorldPlayerMapping;
|
||||
import appeng.util.BlockPosUtils;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
|
||||
@@ -49,6 +50,8 @@ import appeng.util.Platform;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
|
||||
import static appeng.client.render.BlockPosHighlighter.hilightBlock;
|
||||
@@ -68,6 +71,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
private final HashMap<GuiButton,ClientDCInternalInv> guiButtonHashMap = new HashMap<>();
|
||||
private final ArrayList<String> names = new ArrayList<>();
|
||||
private final ArrayList<Object> lines = new ArrayList<>();
|
||||
private final Set<Object> matchedStacks = new HashSet<>();
|
||||
|
||||
private final Map<String, Set<Object>> cachedSearches = new WeakHashMap<>();
|
||||
|
||||
@@ -77,6 +81,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
private PartInterfaceTerminal partInterfaceTerminal;
|
||||
private GuiButton guiButtonHide;
|
||||
private GuiButton guiButtonNextAssembler;
|
||||
private HashMap<ClientDCInternalInv,Integer> dimHashMap = new HashMap<>();
|
||||
|
||||
public GuiInterfaceTerminal( final InventoryPlayer inventoryPlayer, final PartInterfaceTerminal te )
|
||||
{
|
||||
@@ -123,14 +128,6 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
super.onGuiClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isPointInRegion( int rectX, int rectY, int rectWidth, int rectHeight, int pointX, int pointY )
|
||||
{
|
||||
if( searchFieldInputs.isMouseIn( pointX, pointY ) ) drawTooltip( pointX - guiLeft - offsetX, pointY - guiTop , "Inputs OR names" );
|
||||
else if( searchFieldOutputs.isMouseIn( pointX, pointY ) ) drawTooltip( pointX - guiLeft - offsetX, pointY - guiTop, "Outputs OR names" );
|
||||
return super.isPointInRegion( rectX, rectY, rectWidth, rectHeight, pointX, pointY );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG( final int offsetX, final int offsetY, final int mouseX, final int mouseY )
|
||||
{
|
||||
@@ -161,6 +158,8 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
for( int z = 0; z < inv.getInventory().getSlots(); z++ )
|
||||
{
|
||||
this.inventorySlots.inventorySlots.add( new SlotDisconnected( inv, z, z * 18 + 22, 1 + offset ) );
|
||||
if (this.matchedStacks.contains(inv.getInventory().getStackInSlot(z)))
|
||||
drawRect( z * 18 + 22, 1 + offset, z * 18 + 22 + 16, 1 + offset + 16, 0x2A00FF00 );
|
||||
}
|
||||
|
||||
GuiButton guiButton = new GuiImgButton(guiLeft + 4, guiTop + offset + 1, Settings.ACTIONS, ActionItems.HIGHLIGHT_INTERFACE);
|
||||
@@ -186,6 +185,10 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
}
|
||||
offset += 18;
|
||||
}
|
||||
|
||||
if( searchFieldInputs.isMouseIn( mouseX , mouseY ) ) drawTooltip( Mouse.getEventX() * this.width / this.mc.displayWidth - offsetX, mouseY - guiTop, "Inputs OR names" );
|
||||
else if( searchFieldOutputs.isMouseIn( mouseX, mouseY ) ) drawTooltip( Mouse.getEventX() * this.width / this.mc.displayWidth - offsetX, mouseY - guiTop, "Outputs OR names" );
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -217,9 +220,17 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
{
|
||||
BlockPos blockPos = blockPosHashMap.get( guiButtonHashMap.get( this.selectedButton ) );
|
||||
BlockPos blockPos2 = mc.player.getPosition();
|
||||
int dimension = mc.world.provider.getDimension();
|
||||
hilightBlock( blockPos, System.currentTimeMillis() + 500 * BlockPosUtils.getDistance(blockPos, blockPos2), dimension );
|
||||
mc.player.sendStatusMessage( new TextComponentString( "The interface is now highlighted at " + "X: " + blockPos.getX() + " Y: " + blockPos.getY() + " Z: " + blockPos.getZ() ), false );
|
||||
int playerDim = mc.world.provider.getDimension();
|
||||
int interfaceDim = dimHashMap.get( guiButtonHashMap.get( this.selectedButton ) );
|
||||
if( playerDim != interfaceDim )
|
||||
{
|
||||
mc.player.sendStatusMessage( new TextComponentString( "Interface located at dimension: " + interfaceDim + " [" + DimensionManager.getWorld( interfaceDim ).provider.getDimensionType().getName() + "] and cant be highlighted" ), false );
|
||||
}
|
||||
else
|
||||
{
|
||||
hilightBlock( blockPos, System.currentTimeMillis() + 500 * BlockPosUtils.getDistance( blockPos, blockPos2 ), playerDim );
|
||||
mc.player.sendStatusMessage( new TextComponentString( "The interface is now highlighted at " + "X: " + blockPos.getX() + " Y: " + blockPos.getY() + " Z: " + blockPos.getZ() ), false );
|
||||
}
|
||||
mc.player.closeScreen();
|
||||
}
|
||||
|
||||
@@ -325,6 +336,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
final NBTTagCompound invData = in.getCompoundTag( key );
|
||||
final ClientDCInternalInv current = this.getById( id, invData.getLong( "sortBy" ), invData.getString( "un" ) );
|
||||
blockPosHashMap.put( current, NBTUtil.getPosFromTag( invData.getCompoundTag( "pos" )) );
|
||||
dimHashMap.put( current, invData.getInteger( "dim" ));
|
||||
|
||||
for( int x = 0; x < current.getInventory().getSlots(); x++ )
|
||||
{
|
||||
@@ -359,6 +371,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
{
|
||||
this.byName.clear();
|
||||
this.buttonList.clear();
|
||||
this.matchedStacks.clear();
|
||||
|
||||
final String searchFieldInputs = this.searchFieldInputs.getText().toLowerCase();
|
||||
final String searchFieldOutputs = this.searchFieldOutputs.getText().toLowerCase();
|
||||
@@ -377,37 +390,36 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
// Shortcut to skip any filter if search term is ""/empty
|
||||
|
||||
boolean found = (searchFieldInputs.isEmpty() && searchFieldOutputs.isEmpty() && !partInterfaceTerminal.onlyInterfacesWithFreeSlots);
|
||||
boolean interfaceHasFreeSlots = false;
|
||||
|
||||
// Search if the current inventory holds a pattern containing the search term.
|
||||
if( !found )
|
||||
{
|
||||
for( final ItemStack itemStack : entry.getInventory() )
|
||||
{
|
||||
if( !searchFieldInputs.isEmpty() && !searchFieldOutputs.isEmpty() )
|
||||
found = ( this.itemStackMatchesSearchTerm( itemStack, searchFieldInputs, 0 ) || this.itemStackMatchesSearchTerm( itemStack, searchFieldOutputs, 1 ) );
|
||||
else if( !searchFieldInputs.isEmpty() )
|
||||
found = ( this.itemStackMatchesSearchTerm( itemStack, searchFieldInputs, 0 ) );
|
||||
else if( !searchFieldOutputs.isEmpty() )
|
||||
found = ( this.itemStackMatchesSearchTerm( itemStack, searchFieldOutputs, 1 ) );
|
||||
if( found )
|
||||
{
|
||||
break;
|
||||
if( !searchFieldInputs.isEmpty() && !searchFieldOutputs.isEmpty() ) {
|
||||
if (this.itemStackMatchesSearchTerm(itemStack, searchFieldInputs, 0) || this.itemStackMatchesSearchTerm(itemStack, searchFieldOutputs, 1)) {
|
||||
found = true;
|
||||
matchedStacks.add(itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If only Interfaces with empty slots should be shown, check that here
|
||||
boolean interfaceHasFreeSlots = false;
|
||||
if (partInterfaceTerminal.onlyInterfacesWithFreeSlots) {
|
||||
for( final ItemStack itemStack : entry.getInventory() )
|
||||
{
|
||||
if(itemStack.isEmpty()){
|
||||
else if( !searchFieldInputs.isEmpty() ) {
|
||||
if (this.itemStackMatchesSearchTerm(itemStack, searchFieldInputs, 0)) {
|
||||
found = true;
|
||||
matchedStacks.add(itemStack);
|
||||
}
|
||||
}
|
||||
else if( !searchFieldOutputs.isEmpty() ) {
|
||||
if (this.itemStackMatchesSearchTerm(itemStack, searchFieldOutputs, 1)) {
|
||||
found = true;
|
||||
matchedStacks.add(itemStack);
|
||||
}
|
||||
}
|
||||
// If only Interfaces with empty slots should be shown, check that here
|
||||
if(itemStack.isEmpty())
|
||||
interfaceHasFreeSlots = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if found, filter skipped or machine name matching the search term, add it
|
||||
if( found || (entry.getName().toLowerCase().contains( searchFieldInputs ) && entry.getName().toLowerCase().contains( searchFieldOutputs )))
|
||||
{
|
||||
|
||||
@@ -19,11 +19,21 @@
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import appeng.container.interfaces.IJEIGhostIngredients;
|
||||
import appeng.container.slot.SlotFake;
|
||||
import appeng.core.sync.packets.PacketInventoryAction;
|
||||
import appeng.helpers.InventoryAction;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import mezz.jei.api.gui.IGhostIngredientHandler.Target;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.ActionItems;
|
||||
@@ -40,7 +50,7 @@ import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
|
||||
|
||||
public class GuiPatternTerm extends GuiMEMonitorable
|
||||
public class GuiPatternTerm extends GuiMEMonitorable implements IJEIGhostIngredients
|
||||
{
|
||||
|
||||
private static final String BACKGROUND_CRAFTING_MODE = "guis/pattern.png";
|
||||
@@ -67,6 +77,7 @@ public class GuiPatternTerm extends GuiMEMonitorable
|
||||
private GuiImgButton divThreeBtn;
|
||||
private GuiImgButton minusOneBtn;
|
||||
private GuiImgButton maxCountBtn;
|
||||
public Map<Target<?>,Object> mapTargetSlot = new HashMap<>();
|
||||
|
||||
public GuiPatternTerm( final InventoryPlayer inventoryPlayer, final ITerminalHost te )
|
||||
{
|
||||
@@ -274,4 +285,52 @@ public class GuiPatternTerm extends GuiMEMonitorable
|
||||
|
||||
s.yPos = s.getY() + this.ySize - 78 - offsetPlayerSide;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Target<?>> getPhantomTargets(Object ingredient) {
|
||||
if (!(ingredient instanceof ItemStack )) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<Target<?>> targets = new ArrayList<>();
|
||||
for( Slot slot : this.inventorySlots.inventorySlots )
|
||||
{
|
||||
if( slot instanceof SlotFake )
|
||||
{
|
||||
ItemStack itemStack = (ItemStack) ingredient;
|
||||
Target<Object> target = new Target<Object>()
|
||||
{
|
||||
@Override
|
||||
public Rectangle getArea()
|
||||
{
|
||||
return new Rectangle( getGuiLeft() + slot.xPos, getGuiTop() + slot.yPos, 16, 16 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept( Object ingredient )
|
||||
{
|
||||
final PacketInventoryAction p;
|
||||
try
|
||||
{
|
||||
p = new PacketInventoryAction( InventoryAction.PLACE_JEI_GHOST_ITEM, (SlotFake) slot, AEItemStack.fromItemStack( itemStack ) );
|
||||
NetworkHandler.instance().sendToServer( p );
|
||||
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
targets.add( target );
|
||||
mapTargetSlot.putIfAbsent( target, slot );
|
||||
}
|
||||
}
|
||||
return targets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Target<?>, Object> getFakeSlotTargetMap()
|
||||
{
|
||||
return mapTargetSlot;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,24 @@
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import appeng.client.gui.widgets.GuiCustomSlot;
|
||||
import appeng.container.interfaces.IJEIGhostIngredients;
|
||||
import appeng.container.slot.IJEITargetSlot;
|
||||
import appeng.container.slot.SlotFake;
|
||||
import appeng.core.sync.packets.PacketInventoryAction;
|
||||
import appeng.fluids.client.gui.widgets.GuiFluidSlot;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.helpers.InventoryAction;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import mezz.jei.api.gui.IGhostIngredientHandler.Target;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.*;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
@@ -43,9 +59,9 @@ import appeng.parts.automation.PartExportBus;
|
||||
import appeng.parts.automation.PartImportBus;
|
||||
|
||||
|
||||
public class GuiUpgradeable extends AEBaseGui
|
||||
public class GuiUpgradeable extends AEBaseGui implements IJEIGhostIngredients
|
||||
{
|
||||
|
||||
private final Map<Target<?>,Object> mapTargetSlot = new HashMap<>();
|
||||
protected final ContainerUpgradeable cvb;
|
||||
protected final IUpgradeableHost bc;
|
||||
|
||||
@@ -200,4 +216,108 @@ public class GuiUpgradeable extends AEBaseGui
|
||||
NetworkHandler.instance().sendToServer( new PacketConfigButton( this.schedulingMode.getSetting(), backwards ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Target<?>> getPhantomTargets(Object ingredient)
|
||||
{
|
||||
mapTargetSlot.clear();
|
||||
|
||||
FluidStack fluidStack = null;
|
||||
ItemStack itemStack = ItemStack.EMPTY;
|
||||
|
||||
if( ingredient instanceof ItemStack )
|
||||
{
|
||||
itemStack = (ItemStack) ingredient;
|
||||
fluidStack = FluidUtil.getFluidContained( itemStack );
|
||||
}
|
||||
else if( ingredient instanceof FluidStack )
|
||||
{
|
||||
fluidStack = (FluidStack) ingredient;
|
||||
}
|
||||
|
||||
if( !( ingredient instanceof ItemStack ) && !( ingredient instanceof FluidStack ) )
|
||||
return Collections.emptyList();
|
||||
|
||||
List<Target<?>> targets = new ArrayList<>();
|
||||
|
||||
List<IJEITargetSlot> slots = new ArrayList<>();
|
||||
if( this.inventorySlots.inventorySlots.size() > 0 )
|
||||
{
|
||||
for( Slot slot : this.inventorySlots.inventorySlots )
|
||||
{
|
||||
if( slot instanceof SlotFake && ( !itemStack.isEmpty() || this instanceof GuiCellWorkbench && fluidStack != null ) )
|
||||
{
|
||||
slots.add( (IJEITargetSlot) slot );
|
||||
}
|
||||
}
|
||||
}
|
||||
if( this.getGuiSlots().size() > 0 )
|
||||
{
|
||||
for( GuiCustomSlot slot : this.getGuiSlots() )
|
||||
{
|
||||
if( slot instanceof GuiFluidSlot && fluidStack != null )
|
||||
{
|
||||
slots.add( (IJEITargetSlot) slot );
|
||||
}
|
||||
}
|
||||
}
|
||||
for( Object slot : slots )
|
||||
{
|
||||
ItemStack finalItemStack = itemStack;
|
||||
FluidStack finalFluidStack = fluidStack;
|
||||
Target<Object> targetItem = new Target<Object>()
|
||||
{
|
||||
@Override
|
||||
public Rectangle getArea()
|
||||
{
|
||||
if( slot instanceof SlotFake )
|
||||
return new Rectangle( getGuiLeft() + ( (SlotFake) slot ).xPos, getGuiTop() + ( (SlotFake) slot ).yPos, 16, 16 );
|
||||
else
|
||||
{
|
||||
return new Rectangle( getGuiLeft() + ( (GuiFluidSlot) slot ).xPos(), getGuiTop() + ( (GuiFluidSlot) slot ).yPos(), 16, 16 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept( Object ingredient )
|
||||
{
|
||||
PacketInventoryAction p = null;
|
||||
try
|
||||
{
|
||||
if( slot instanceof SlotFake )
|
||||
{
|
||||
if( finalItemStack.isEmpty() && finalFluidStack != null )
|
||||
{
|
||||
p = new PacketInventoryAction( InventoryAction.PLACE_JEI_GHOST_ITEM, (IJEITargetSlot) slot, AEItemStack.fromItemStack( FluidUtil.getFilledBucket( finalFluidStack ) ) );
|
||||
}
|
||||
else if( !finalItemStack.isEmpty() )
|
||||
{
|
||||
p = new PacketInventoryAction( InventoryAction.PLACE_JEI_GHOST_ITEM, (IJEITargetSlot) slot, AEItemStack.fromItemStack( finalItemStack ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( finalFluidStack == null ) return;
|
||||
p = new PacketInventoryAction( InventoryAction.PLACE_JEI_GHOST_ITEM, (IJEITargetSlot) slot, AEItemStack.fromItemStack( AEFluidStack.fromFluidStack( finalFluidStack ).asItemStackRepresentation() ) );
|
||||
}
|
||||
NetworkHandler.instance().sendToServer( p );
|
||||
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
targets.add( targetItem );
|
||||
mapTargetSlot.putIfAbsent( targetItem, slot );
|
||||
}
|
||||
return targets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Target<?>, Object> getFakeSlotTargetMap()
|
||||
{
|
||||
return mapTargetSlot;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,56 +159,58 @@ public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorH
|
||||
@Override
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
if( Platform.isServer() && this.getMonitor() != null && !this.list.isEmpty() )
|
||||
if( Platform.isServer() && this.getMonitor() != null )
|
||||
{
|
||||
try
|
||||
if( this.getEstimatedTime() >= 0 )
|
||||
{
|
||||
if( this.getEstimatedTime() >= 0 )
|
||||
final long elapsedTime = this.getMonitor().getElapsedTime();
|
||||
final double remainingItems = this.getMonitor().getRemainingItemCount();
|
||||
final double startItems = this.getMonitor().getStartItemCount();
|
||||
final long eta = (long) ( elapsedTime / Math.max( 1d, ( startItems - remainingItems ) ) * remainingItems );
|
||||
this.setEstimatedTime( eta );
|
||||
}
|
||||
if( !this.list.isEmpty() )
|
||||
{
|
||||
try
|
||||
{
|
||||
final long elapsedTime = this.getMonitor().getElapsedTime();
|
||||
final double remainingItems = this.getMonitor().getRemainingItemCount();
|
||||
final double startItems = this.getMonitor().getStartItemCount();
|
||||
final long eta = (long) ( elapsedTime / Math.max( 1d, ( startItems - remainingItems ) ) * remainingItems );
|
||||
this.setEstimatedTime( eta );
|
||||
}
|
||||
final PacketMEInventoryUpdate a = new PacketMEInventoryUpdate( (byte) 0 );
|
||||
final PacketMEInventoryUpdate b = new PacketMEInventoryUpdate( (byte) 1 );
|
||||
final PacketMEInventoryUpdate c = new PacketMEInventoryUpdate( (byte) 2 );
|
||||
|
||||
final PacketMEInventoryUpdate a = new PacketMEInventoryUpdate( (byte) 0 );
|
||||
final PacketMEInventoryUpdate b = new PacketMEInventoryUpdate( (byte) 1 );
|
||||
final PacketMEInventoryUpdate c = new PacketMEInventoryUpdate( (byte) 2 );
|
||||
|
||||
for( final IAEItemStack out : this.list )
|
||||
{
|
||||
a.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.STORAGE ) );
|
||||
b.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.ACTIVE ) );
|
||||
c.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.PENDING ) );
|
||||
}
|
||||
|
||||
this.list.resetStatus();
|
||||
|
||||
for( final Object g : this.listeners )
|
||||
{
|
||||
if( g instanceof EntityPlayer )
|
||||
for( final IAEItemStack out : this.list )
|
||||
{
|
||||
if( !a.isEmpty() )
|
||||
{
|
||||
NetworkHandler.instance().sendTo( a, (EntityPlayerMP) g );
|
||||
}
|
||||
a.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.STORAGE ) );
|
||||
b.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.ACTIVE ) );
|
||||
c.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.PENDING ) );
|
||||
}
|
||||
|
||||
if( !b.isEmpty() )
|
||||
{
|
||||
NetworkHandler.instance().sendTo( b, (EntityPlayerMP) g );
|
||||
}
|
||||
this.list.resetStatus();
|
||||
|
||||
if( !c.isEmpty() )
|
||||
for( final Object g : this.listeners )
|
||||
{
|
||||
if( g instanceof EntityPlayer )
|
||||
{
|
||||
NetworkHandler.instance().sendTo( c, (EntityPlayerMP) g );
|
||||
if( !a.isEmpty() )
|
||||
{
|
||||
NetworkHandler.instance().sendTo( a, (EntityPlayerMP) g );
|
||||
}
|
||||
|
||||
if( !b.isEmpty() )
|
||||
{
|
||||
NetworkHandler.instance().sendTo( b, (EntityPlayerMP) g );
|
||||
}
|
||||
|
||||
if( !c.isEmpty() )
|
||||
{
|
||||
NetworkHandler.instance().sendTo( c, (EntityPlayerMP) g );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( final IOException e )
|
||||
{
|
||||
// :P
|
||||
catch( final IOException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
super.detectAndSendChanges();
|
||||
|
||||
@@ -215,35 +215,48 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer
|
||||
final IItemHandler theSlot = new WrapperFilteredItemHandler( new WrapperRangeItemHandler( inv.server, slot, slot + 1 ), new PatternSlotFilter() );
|
||||
final InventoryAdaptor interfaceSlot = new AdaptorItemHandler( theSlot );
|
||||
|
||||
switch( action )
|
||||
IItemHandler interfaceHandler = inv.server;
|
||||
boolean canInsert = true;
|
||||
|
||||
switch ( action )
|
||||
{
|
||||
case PICKUP_OR_SET_DOWN:
|
||||
|
||||
if( hasItemInHand )
|
||||
{
|
||||
ItemStack inSlot = theSlot.getStackInSlot( 0 );
|
||||
if( inSlot.isEmpty() )
|
||||
for( int s = 0; s < interfaceHandler.getSlots(); s++ )
|
||||
{
|
||||
player.inventory.setItemStack( interfaceSlot.addItems( player.inventory.getItemStack() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
inSlot = inSlot.copy();
|
||||
final ItemStack inHand = player.inventory.getItemStack().copy();
|
||||
|
||||
ItemHandlerUtil.setStackInSlot( theSlot, 0, ItemStack.EMPTY );
|
||||
player.inventory.setItemStack( ItemStack.EMPTY );
|
||||
|
||||
player.inventory.setItemStack( interfaceSlot.addItems( inHand.copy() ) );
|
||||
|
||||
if( player.inventory.getItemStack().isEmpty() )
|
||||
if( Platform.itemComparisons().isSameItem( interfaceHandler.getStackInSlot( s ), player.inventory.getItemStack() ) )
|
||||
{
|
||||
player.inventory.setItemStack( inSlot );
|
||||
canInsert = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( canInsert )
|
||||
{
|
||||
ItemStack inSlot = theSlot.getStackInSlot( 0 );
|
||||
if( inSlot.isEmpty() )
|
||||
{
|
||||
player.inventory.setItemStack( interfaceSlot.addItems( player.inventory.getItemStack() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
player.inventory.setItemStack( inHand );
|
||||
ItemHandlerUtil.setStackInSlot( theSlot, 0, inSlot );
|
||||
inSlot = inSlot.copy();
|
||||
final ItemStack inHand = player.inventory.getItemStack().copy();
|
||||
|
||||
ItemHandlerUtil.setStackInSlot( theSlot, 0, ItemStack.EMPTY );
|
||||
player.inventory.setItemStack( ItemStack.EMPTY );
|
||||
|
||||
player.inventory.setItemStack( interfaceSlot.addItems( inHand.copy() ) );
|
||||
|
||||
if( player.inventory.getItemStack().isEmpty() )
|
||||
{
|
||||
player.inventory.setItemStack( inSlot );
|
||||
}
|
||||
else
|
||||
{
|
||||
player.inventory.setItemStack( inHand );
|
||||
ItemHandlerUtil.setStackInSlot( theSlot, 0, inSlot );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -254,17 +267,27 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer
|
||||
|
||||
break;
|
||||
case SPLIT_OR_PLACE_SINGLE:
|
||||
|
||||
if( hasItemInHand )
|
||||
{
|
||||
ItemStack extra = playerHand.removeItems( 1, ItemStack.EMPTY, null );
|
||||
if( !extra.isEmpty() && !interfaceSlot.containsItems())
|
||||
for( int s = 0; s < interfaceHandler.getSlots(); s++ )
|
||||
{
|
||||
extra = interfaceSlot.addItems( extra );
|
||||
if( Platform.itemComparisons().isSameItem( interfaceHandler.getStackInSlot( s ), player.inventory.getItemStack() ) )
|
||||
{
|
||||
canInsert = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( !extra.isEmpty() )
|
||||
if( canInsert )
|
||||
{
|
||||
playerHand.addItems( extra );
|
||||
ItemStack extra = playerHand.removeItems( 1, ItemStack.EMPTY, null );
|
||||
if( !extra.isEmpty() && !interfaceSlot.containsItems() )
|
||||
{
|
||||
extra = interfaceSlot.addItems( extra );
|
||||
}
|
||||
if( !extra.isEmpty() )
|
||||
{
|
||||
playerHand.addItems( extra );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( !is.isEmpty() )
|
||||
@@ -380,7 +403,8 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer
|
||||
{
|
||||
tag.setLong( "sortBy", inv.sortBy );
|
||||
tag.setString( "un", inv.unlocalizedName );
|
||||
tag.setTag("pos", NBTUtil.createPosTag( inv.pos ) );
|
||||
tag.setTag( "pos", NBTUtil.createPosTag( inv.pos ) );
|
||||
tag.setInteger( "dim", inv.dim );
|
||||
}
|
||||
|
||||
for( int x = 0; x < length; x++ )
|
||||
@@ -412,6 +436,7 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer
|
||||
private final IItemHandler client;
|
||||
private final IItemHandler server;
|
||||
private final BlockPos pos;
|
||||
private final int dim;
|
||||
|
||||
public InvTracker( final DualityInterface dual, final IItemHandler patterns, final String unlocalizedName )
|
||||
{
|
||||
@@ -420,6 +445,7 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer
|
||||
this.unlocalizedName = unlocalizedName;
|
||||
this.sortBy = dual.getSortValue();
|
||||
this.pos = dual.getLocation().getPos();
|
||||
this.dim = dual.getLocation().getWorld().provider.getDimension();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import appeng.container.slot.*;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
@@ -51,12 +52,6 @@ import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.container.ContainerNull;
|
||||
import appeng.container.guisync.GuiSync;
|
||||
import appeng.container.slot.IOptionalSlotHost;
|
||||
import appeng.container.slot.OptionalSlotFake;
|
||||
import appeng.container.slot.SlotFakeCraftingMatrix;
|
||||
import appeng.container.slot.SlotPatternOutputs;
|
||||
import appeng.container.slot.SlotPatternTerm;
|
||||
import appeng.container.slot.SlotRestrictedInput;
|
||||
import appeng.core.sync.packets.PacketPatternSlot;
|
||||
import appeng.helpers.IContainerCraftingPacket;
|
||||
import appeng.items.storage.ItemViewCell;
|
||||
@@ -132,6 +127,28 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
|
||||
this.updateOrderOfOutputSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot( final EntityPlayer p, final int idx )
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
if( this.inventorySlots.get( idx ) instanceof SlotPlayerInv || this.inventorySlots.get( idx ) instanceof SlotPlayerHotBar )
|
||||
{
|
||||
final AppEngSlot clickSlot = ( AppEngSlot ) this.inventorySlots.get( idx ); // require AE SLots!
|
||||
ItemStack itemStack = clickSlot.getStack();
|
||||
if( AEApi.instance().definitions().materials().blankPattern().isSameAs( itemStack ) )
|
||||
{
|
||||
IItemHandler patternInv = this.getPatternTerminal().getInventoryByName( "pattern" );
|
||||
ItemStack remainder = patternInv.insertItem( 0, itemStack, false );
|
||||
clickSlot.putStack( remainder );
|
||||
}
|
||||
}
|
||||
return super.transferStackInSlot( p, idx );
|
||||
}
|
||||
|
||||
|
||||
private void updateOrderOfOutputSlots()
|
||||
{
|
||||
if( !this.isCraftingMode() )
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package appeng.container.interfaces;
|
||||
|
||||
import mezz.jei.api.gui.IGhostIngredientHandler.Target;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public interface IJEIGhostIngredients
|
||||
{
|
||||
List<Target<?>> getPhantomTargets( Object ingredient );
|
||||
|
||||
default Map<Target<?>, Object> getFakeSlotTargetMap(){
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package appeng.container.slot;
|
||||
|
||||
public interface IJEITargetSlot {
|
||||
}
|
||||
@@ -24,7 +24,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
|
||||
public class SlotFake extends AppEngSlot
|
||||
public class SlotFake extends AppEngSlot implements IJEITargetSlot
|
||||
{
|
||||
|
||||
public SlotFake( final IItemHandler inv, final int idx, final int x, final int y )
|
||||
|
||||
@@ -164,7 +164,6 @@ public enum AEFeature
|
||||
PATTERNS( "Patterns", Constants.CATEGORY_CRAFTING_FEATURES ),
|
||||
CRAFTING_CPU( "CraftingCPU", Constants.CATEGORY_CRAFTING_FEATURES ),
|
||||
CRAFTING_MANAGER_FALLBACK( "CraftingManagerFallback", Constants.CATEGORY_CRAFTING_FEATURES, "Use CraftingManager to find an alternative recipe, after a pattern rejected an ingredient. Should be enabled to avoid issues, but can have a minor performance impact." ),
|
||||
INSANE_BLOCKING_MODE( "InsaneBlockingMode", Constants.CATEGORY_CRAFTING_FEATURES, "Use the default AE2 blocking mode that doesn't work on any machines" ),
|
||||
|
||||
BASIC_CARDS( "BasicCards", Constants.CATEGORY_UPGRADES ),
|
||||
ADVANCED_CARDS( "AdvancedCards", Constants.CATEGORY_UPGRADES ),
|
||||
|
||||
@@ -20,7 +20,16 @@ package appeng.core.sync.packets;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.container.slot.IJEITargetSlot;
|
||||
import appeng.container.slot.SlotFake;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.fluids.client.gui.widgets.GuiFluidSlot;
|
||||
import appeng.fluids.container.ContainerFluidConfigurable;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
@@ -40,6 +49,7 @@ import appeng.core.sync.network.INetworkInfo;
|
||||
import appeng.helpers.InventoryAction;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
|
||||
public class PacketInventoryAction extends AppEngPacket
|
||||
@@ -57,6 +67,7 @@ public class PacketInventoryAction extends AppEngPacket
|
||||
this.slot = stream.readInt();
|
||||
this.id = stream.readLong();
|
||||
final boolean hasItem = stream.readBoolean();
|
||||
|
||||
if( hasItem )
|
||||
{
|
||||
this.slotItem = AEItemStack.fromPacket( stream );
|
||||
@@ -70,7 +81,6 @@ public class PacketInventoryAction extends AppEngPacket
|
||||
// api
|
||||
public PacketInventoryAction( final InventoryAction action, final int slot, final IAEItemStack slotItem ) throws IOException
|
||||
{
|
||||
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
throw new IllegalStateException( "invalid packet, client cannot post inv actions with stacks." );
|
||||
@@ -101,6 +111,36 @@ public class PacketInventoryAction extends AppEngPacket
|
||||
this.configureWrite( data );
|
||||
}
|
||||
|
||||
public PacketInventoryAction(final InventoryAction action, final IJEITargetSlot slot, final IAEItemStack slotItem ) throws IOException
|
||||
{
|
||||
|
||||
this.action = action;
|
||||
if (slot instanceof SlotFake)
|
||||
this.slot = ((SlotFake) slot).slotNumber;
|
||||
else this.slot = ((GuiFluidSlot) slot).getId();
|
||||
this.id = 0;
|
||||
this.slotItem = slotItem;
|
||||
|
||||
final ByteBuf data = Unpooled.buffer();
|
||||
|
||||
data.writeInt( this.getPacketID() );
|
||||
data.writeInt( action.ordinal() );
|
||||
data.writeInt( this.slot );
|
||||
data.writeLong( this.id );
|
||||
|
||||
if( slotItem == null )
|
||||
{
|
||||
data.writeBoolean( false );
|
||||
}
|
||||
else
|
||||
{
|
||||
data.writeBoolean( true );
|
||||
slotItem.writeToPacket( data );
|
||||
}
|
||||
|
||||
this.configureWrite( data );
|
||||
}
|
||||
|
||||
// api
|
||||
public PacketInventoryAction( final InventoryAction action, final int slot, final long id )
|
||||
{
|
||||
@@ -150,6 +190,48 @@ public class PacketInventoryAction extends AppEngPacket
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( this.action == InventoryAction.PLACE_JEI_GHOST_ITEM )
|
||||
{
|
||||
if( sender.openContainer.inventorySlots.get( this.slot ) instanceof SlotFake )
|
||||
{
|
||||
if( this.slotItem != null )
|
||||
{
|
||||
sender.openContainer.inventorySlots.get( this.slot ).putStack( this.slotItem.createItemStack() );
|
||||
if( sender.openContainer.inventorySlots.get( this.slot ).getStack().isEmpty() )
|
||||
{
|
||||
IAEFluidStack aefs = AEFluidStack.fromNBT( this.slotItem.getDefinition().getTagCompound() );
|
||||
if( aefs != null )
|
||||
{
|
||||
FluidStack fluid = aefs.getFluidStack();
|
||||
sender.openContainer.inventorySlots.get( this.slot ).putStack( AEFluidStack.fromFluidStack( fluid ).asItemStackRepresentation() );
|
||||
}
|
||||
}
|
||||
}
|
||||
else sender.openContainer.inventorySlots.get( this.slot ).putStack( ItemStack.EMPTY );
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance().sendTo( new PacketInventoryAction( InventoryAction.UPDATE_HAND, 0, AEItemStack.fromItemStack( ItemStack.EMPTY ) ), sender );
|
||||
}
|
||||
catch( final IOException e )
|
||||
{
|
||||
AELog.debug( e );
|
||||
}
|
||||
}
|
||||
|
||||
if( sender.openContainer instanceof ContainerFluidConfigurable )
|
||||
{
|
||||
if( this.slotItem != null )
|
||||
{
|
||||
IAEFluidStack aefs = AEFluidStack.fromNBT( this.slotItem.getDefinition().getTagCompound() );
|
||||
if( aefs != null )
|
||||
{
|
||||
aefs.setStackSize( 1000 );
|
||||
( (ContainerFluidConfigurable) sender.openContainer ).getFluidConfigInventory().setFluidInSlot( this.slot, aefs );
|
||||
NetworkHandler.instance().sendToServer( new PacketFluidSlot( Collections.singletonMap( this.slot, aefs ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
baseContainer.doAction( sender, this.action, this.slot, this.id );
|
||||
|
||||
@@ -215,7 +215,7 @@ public class PacketJEIRecipe extends AppEngPacket
|
||||
IAEItemStack mostDamaged = null;
|
||||
for( IAEItemStack is : outList )
|
||||
{
|
||||
if( !is.isCraftable() && is.getItem().isDamageable() )
|
||||
if( !is.isCraftable() )
|
||||
{
|
||||
if( mostDamaged == null || mostDamaged.getItemDamage() < is.getItemDamage() )
|
||||
{
|
||||
@@ -285,6 +285,7 @@ public class PacketJEIRecipe extends AppEngPacket
|
||||
IItemHandler outputSlots = cct.getInventoryByName( "output" );
|
||||
for( int i = 0; i < this.output.length; ++i )
|
||||
{
|
||||
if( this.output[i] == null ) continue;
|
||||
ItemHandlerUtil.setStackInSlot( outputSlots, i, this.output[i] );
|
||||
}
|
||||
}
|
||||
@@ -303,7 +304,7 @@ public class PacketJEIRecipe extends AppEngPacket
|
||||
{
|
||||
for( ItemStack option : this.recipe[slot] )
|
||||
{
|
||||
if( is.isItemEqual( option ) )
|
||||
if( ItemStack.areItemStacksEqual( is, option ) )
|
||||
{
|
||||
return is;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,9 @@ import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.me.helpers.PlayerSource;
|
||||
import appeng.util.inv.ItemListIgnoreCrafting;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
|
||||
|
||||
public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
||||
@@ -307,8 +309,15 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
||||
|
||||
if( result == null || result.getStackSize() != extra.getStackSize() )
|
||||
{
|
||||
if( src.player().isPresent() )
|
||||
{
|
||||
if( result == null )
|
||||
src.player().get().sendStatusMessage( new TextComponentString( "System reported " + extra.getStackSize() + " " + extra.getDefinition().getDisplayName() + " available but could not extract anything" ), false );
|
||||
else
|
||||
src.player().get().sendStatusMessage( new TextComponentString( "System reported " + extra.getStackSize() + " " + extra.getDefinition().getDisplayName() + " available but could only extract " + result.getStackSize() ), false );
|
||||
}
|
||||
failed = true;
|
||||
break;
|
||||
if( !src.player().isPresent() ) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,6 +90,13 @@ public class GuiFluidLevelEmitter extends GuiUpgradeable
|
||||
this.level.drawTextBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG( int offsetX, int offsetY, int mouseX, int mouseY )
|
||||
{
|
||||
if( isPointInRegion( 24, 43,89,this.fontRenderer.FONT_HEIGHT,mouseX,mouseY ) ) drawTooltip( mouseX - guiLeft - 7, mouseY - guiTop + 25, "Amount in millibuckets" );
|
||||
super.drawFG( offsetX, offsetY, mouseX, mouseY );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean drawUpgrades()
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ package appeng.fluids.client.gui.widgets;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import appeng.container.slot.IJEITargetSlot;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
@@ -23,7 +24,7 @@ import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.fluids.util.IAEFluidTank;
|
||||
|
||||
|
||||
public class GuiFluidSlot extends GuiCustomSlot
|
||||
public class GuiFluidSlot extends GuiCustomSlot implements IJEITargetSlot
|
||||
{
|
||||
private final IAEFluidTank fluids;
|
||||
private final int slot;
|
||||
|
||||
@@ -264,18 +264,19 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
|
||||
@Override
|
||||
public void postChange( final IBaseMonitor<IAEFluidStack> monitor, final Iterable<IAEFluidStack> change, final IActionSource source )
|
||||
{
|
||||
try
|
||||
if( source == this.source || source.machine().map( machine -> machine == this ).orElse( false ) )
|
||||
{
|
||||
if( this.getProxy().isActive() )
|
||||
try
|
||||
{
|
||||
this.getProxy()
|
||||
.getStorage()
|
||||
.postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ), change, this.source );
|
||||
if( this.getProxy().isActive() )
|
||||
{
|
||||
this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ), change, this.source );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :(
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,22 +19,22 @@
|
||||
package appeng.helpers;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.integration.modules.gregtech.GTCEInventoryAdaptor;
|
||||
import appeng.util.*;
|
||||
import appeng.util.inv.*;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import de.ellpeck.actuallyadditions.api.tile.IPhantomTile;
|
||||
import gregtech.api.block.machines.BlockMachine;
|
||||
import gregtech.api.metatileentity.MetaTileEntity;
|
||||
import gregtech.api.metatileentity.MetaTileEntityHolder;
|
||||
import gregtech.api.metatileentity.TieredMetaTileEntity;
|
||||
import gregtech.api.metatileentity.WorkableTieredMetaTileEntity;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Items;
|
||||
@@ -93,8 +93,6 @@ import appeng.api.util.AEPartLocation;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.capabilities.Capabilities;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
@@ -106,10 +104,6 @@ import appeng.parts.automation.StackUpgradeInventory;
|
||||
import appeng.parts.automation.UpgradeInventory;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.util.inv.AdaptorItemHandler;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.IInventoryDestination;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
import static gregtech.api.block.machines.BlockMachine.getMetaTileEntity;
|
||||
@@ -148,6 +142,8 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
private IMEInventory<IAEItemStack> destination;
|
||||
private int isWorking = -1;
|
||||
private final Accessor accessor = new Accessor();
|
||||
private EnumSet<EnumFacing> visitedFaces = EnumSet.noneOf( EnumFacing.class );
|
||||
private EnumMap<EnumFacing,List<ItemStack>> waitingToSendFacing = new EnumMap<>(EnumFacing.class);
|
||||
private GTCEInventoryAdaptor GTad;
|
||||
|
||||
public DualityInterface( final AENetworkProxy networkProxy, final IInterfaceHost ih )
|
||||
@@ -242,6 +238,27 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
}
|
||||
}
|
||||
data.setTag( "waitingToSend", waitingToSend );
|
||||
|
||||
NBTTagCompound sidedWaitList = new NBTTagCompound();
|
||||
|
||||
if (this.waitingToSendFacing != null)
|
||||
{
|
||||
for( EnumFacing s : this.iHost.getTargets() )
|
||||
{
|
||||
NBTTagList waitingListSided = new NBTTagList();
|
||||
if (this.waitingToSendFacing.containsKey( s ))
|
||||
{
|
||||
for( final ItemStack is : this.waitingToSendFacing.get( s ) )
|
||||
{
|
||||
final NBTTagCompound item = new NBTTagCompound();
|
||||
is.writeToNBT( item );
|
||||
waitingListSided.appendTag( item );
|
||||
}
|
||||
sidedWaitList.setTag( s.name(), waitingListSided );
|
||||
}
|
||||
}
|
||||
}
|
||||
data.setTag( "sidedWaitList", sidedWaitList );
|
||||
}
|
||||
|
||||
public void readFromNBT( final NBTTagCompound data )
|
||||
@@ -261,6 +278,23 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
}
|
||||
}
|
||||
|
||||
this.waitingToSendFacing = null;
|
||||
final NBTTagCompound waitingListSided = data.getCompoundTag("sidedWaitList");
|
||||
|
||||
for (EnumFacing s : EnumFacing.values())
|
||||
if (waitingListSided.hasKey( s.name() )) {
|
||||
NBTTagList w = waitingListSided.getTagList( s.name(), 10 );
|
||||
for( int x = 0; x < w.tagCount(); x++ )
|
||||
{
|
||||
final NBTTagCompound c = w.getCompoundTagAt( x );
|
||||
if( c != null )
|
||||
{
|
||||
final ItemStack is = new ItemStack( c );
|
||||
this.addToSendListFacing( is , EnumFacing.getFront( s.getIndex() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.craftingTracker.readFromNBT( data );
|
||||
this.upgrades.readFromNBT( data, "upgrades" );
|
||||
this.config.readFromNBT( data, "config" );
|
||||
@@ -296,6 +330,30 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
}
|
||||
}
|
||||
|
||||
private void addToSendListFacing( final ItemStack is, EnumFacing f )
|
||||
{
|
||||
if( is.isEmpty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (this.waitingToSendFacing == null){
|
||||
this.waitingToSendFacing = new EnumMap<>(EnumFacing.class);
|
||||
}
|
||||
|
||||
this.waitingToSendFacing.computeIfAbsent( f, k -> new ArrayList<>() );
|
||||
|
||||
this.waitingToSendFacing.get( f ).add( is );
|
||||
|
||||
try
|
||||
{
|
||||
this.gridProxy.getTick().wakeDevice( this.gridProxy.getNode() );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
private void readConfig()
|
||||
{
|
||||
this.hasConfig = false;
|
||||
@@ -393,24 +451,22 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasWorkToDo()
|
||||
{
|
||||
if( this.hasItemsToSend() )
|
||||
{
|
||||
private boolean hasWorkToDo() {
|
||||
|
||||
if (hasItemsToSend()){
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
for( final IAEItemStack requiredWork : this.requireWork )
|
||||
{
|
||||
if( requiredWork != null )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
if(hasItemsToSendFacing()){
|
||||
return true;
|
||||
}
|
||||
|
||||
for (final IAEItemStack requiredWork : this.requireWork) {
|
||||
if (requiredWork != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void updatePlan( final int slot )
|
||||
@@ -515,6 +571,21 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
return this.waitingToSend != null && !this.waitingToSend.isEmpty();
|
||||
}
|
||||
|
||||
private boolean hasItemsToSendFacing()
|
||||
{
|
||||
if (waitingToSendFacing != null)
|
||||
{
|
||||
for( EnumFacing enumFacing : waitingToSendFacing.keySet() )
|
||||
{
|
||||
if( !waitingToSendFacing.get( enumFacing ).isEmpty() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert( final ItemStack stack )
|
||||
{
|
||||
@@ -586,11 +657,21 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
//Previous version might have items saved in this list
|
||||
//recover them
|
||||
if( this.hasItemsToSend() )
|
||||
{
|
||||
this.pushItemsOut( this.iHost.getTargets() );
|
||||
}
|
||||
|
||||
if (hasItemsToSendFacing())
|
||||
{
|
||||
for( EnumFacing enumFacing : waitingToSendFacing.keySet() )
|
||||
{
|
||||
this.pushItemsOut( enumFacing );
|
||||
}
|
||||
}
|
||||
|
||||
final boolean couldDoWork = this.updateStorage();
|
||||
return this.hasWorkToDo() ? ( couldDoWork ? TickRateModulation.URGENT : TickRateModulation.SLOWER ) : TickRateModulation.SLEEP;
|
||||
}
|
||||
@@ -651,6 +732,47 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
}
|
||||
}
|
||||
|
||||
private void pushItemsOut( final EnumFacing s )
|
||||
{
|
||||
if (!this.waitingToSendFacing.containsKey(s) ||
|
||||
(this.waitingToSendFacing.containsKey(s) && this.waitingToSendFacing.get( s ).isEmpty())) {
|
||||
return;
|
||||
}
|
||||
|
||||
final TileEntity tile = this.iHost.getTileEntity();
|
||||
final World w = tile.getWorld();
|
||||
|
||||
final TileEntity te = w.getTileEntity( tile.getPos().offset( s ) );
|
||||
if( te == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
final Iterator<ItemStack> i = this.waitingToSendFacing.get( s ).iterator();
|
||||
while ( i.hasNext() )
|
||||
{
|
||||
ItemStack whatToSend = i.next();
|
||||
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor( te, s.getOpposite() );
|
||||
if( ad != null )
|
||||
{
|
||||
final ItemStack result = ad.addItems( whatToSend );
|
||||
if( !result.isEmpty() )
|
||||
{
|
||||
whatToSend.setCount( whatToSend.getCount() - ( whatToSend.getCount() - result.getCount() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( this.waitingToSendFacing.get( s ).isEmpty() )
|
||||
{
|
||||
this.waitingToSendFacing.remove( s );
|
||||
}
|
||||
}
|
||||
|
||||
private boolean updateStorage()
|
||||
{
|
||||
boolean didSomething = false;
|
||||
@@ -913,13 +1035,9 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
};
|
||||
}
|
||||
|
||||
private static boolean invIsBlocked( InventoryAdaptor inv )
|
||||
private boolean invIsBlocked( InventoryAdaptor inv )
|
||||
{
|
||||
if( AEConfig.instance().isFeatureEnabled( AEFeature.INSANE_BLOCKING_MODE ) )
|
||||
{
|
||||
return !inv.simulateRemove( 1, ItemStack.EMPTY, null ).isEmpty();
|
||||
}
|
||||
else return inv.containsItems();
|
||||
return (inv.containsItems());
|
||||
}
|
||||
|
||||
private static boolean invIsBlockedGTCE( GTCEInventoryAdaptor inv )
|
||||
@@ -930,7 +1048,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
@Override
|
||||
public boolean pushPattern( final ICraftingPatternDetails patternDetails, final InventoryCrafting table )
|
||||
{
|
||||
if( this.hasItemsToSend() || !this.gridProxy.isActive() || !this.craftingList.contains( patternDetails ) )
|
||||
if( this.hasItemsToSend() || this.hasItemsToSendFacing() || !this.gridProxy.isActive() || !this.craftingList.contains( patternDetails ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -938,8 +1056,12 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
final TileEntity tile = this.iHost.getTileEntity();
|
||||
final World w = tile.getWorld();
|
||||
|
||||
final EnumSet<EnumFacing> possibleDirections = this.iHost.getTargets();
|
||||
for( final EnumFacing s : possibleDirections )
|
||||
if( this.visitedFaces.isEmpty() )
|
||||
{
|
||||
this.visitedFaces = this.iHost.getTargets();
|
||||
}
|
||||
|
||||
for( final EnumFacing s : visitedFaces )
|
||||
{
|
||||
final TileEntity te = w.getTileEntity( tile.getPos().offset( s ) );
|
||||
if( te instanceof IInterfaceHost )
|
||||
@@ -948,6 +1070,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
{
|
||||
if( ( (IInterfaceHost) te ).getInterfaceDuality().sameGrid( this.gridProxy.getGrid() ) )
|
||||
{
|
||||
visitedFaces.remove( s );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -962,6 +1085,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
final ICraftingMachine cm = (ICraftingMachine) te;
|
||||
if( cm.acceptsPlans() )
|
||||
{
|
||||
visitedFaces.remove( s );
|
||||
if( cm.pushPattern( patternDetails, table, s.getOpposite() ) )
|
||||
{
|
||||
return true;
|
||||
@@ -975,53 +1099,67 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
{
|
||||
if( this.isBlocking() )
|
||||
{
|
||||
if( te.getBlockType().getRegistryName().getResourceDomain().equals( "gregtech" ) )
|
||||
IPhantomTile phantomTE = null;
|
||||
if( Loader.isModLoaded( "actuallyadditions" ) && Loader.isModLoaded( "gregtech" ) && te instanceof IPhantomTile )
|
||||
{
|
||||
GTad = GTCEInventoryAdaptor.getAdaptor( te, s.getOpposite() );
|
||||
if( invIsBlockedGTCE( GTad ) )
|
||||
phantomTE = ( (IPhantomTile) te );
|
||||
if( phantomTE.hasBoundPosition() )
|
||||
{
|
||||
TileEntity phantom = w.getTileEntity( phantomTE.getBoundPosition() );
|
||||
if( phantom instanceof MetaTileEntityHolder && isGTCEblocked( phantom, s ) )
|
||||
{
|
||||
visitedFaces.remove( s );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if( Loader.isModLoaded( "gregtech" ) && te instanceof MetaTileEntityHolder )
|
||||
{
|
||||
if( isGTCEblocked( te, s ) )
|
||||
{
|
||||
visitedFaces.remove( s );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
else if( invIsBlocked( ad ) )
|
||||
{
|
||||
if( invIsBlocked( ad ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
visitedFaces.remove( s );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if( this.acceptsItems( ad, table ) )
|
||||
{
|
||||
visitedFaces.remove( s );
|
||||
for( int x = 0; x < table.getSizeInventory(); x++ )
|
||||
{
|
||||
final ItemStack is = table.getStackInSlot( x );
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
final ItemStack added = ad.addItems( is );
|
||||
this.addToSendList( added );
|
||||
addToSendListFacing( is, s );
|
||||
}
|
||||
}
|
||||
this.pushItemsOut( possibleDirections );
|
||||
pushItemsOut( s );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
visitedFaces.remove( s );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBusy()
|
||||
{
|
||||
if( this.hasItemsToSend() )
|
||||
boolean busy = false;
|
||||
|
||||
if( this.hasItemsToSend() || hasItemsToSendFacing() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean busy = false;
|
||||
|
||||
if( this.isBlocking() )
|
||||
{
|
||||
final EnumSet<EnumFacing> possibleDirections = this.iHost.getTargets();
|
||||
@@ -1033,27 +1171,38 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
for( final EnumFacing s : possibleDirections )
|
||||
{
|
||||
final TileEntity te = w.getTileEntity( tile.getPos().offset( s ) );
|
||||
IPhantomTile phantomTE = null;
|
||||
|
||||
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor( te, s.getOpposite() );
|
||||
if( ad != null )
|
||||
{
|
||||
if( te.getBlockType().getRegistryName().getResourceDomain().equals( "gregtech" ) )
|
||||
if( Loader.isModLoaded( "actuallyadditions") && Loader.isModLoaded( "gregtech" ) && te instanceof IPhantomTile )
|
||||
{
|
||||
GTad = GTCEInventoryAdaptor.getAdaptor( te, s.getOpposite() );
|
||||
if( !invIsBlockedGTCE( GTad ) )
|
||||
phantomTE = ( (IPhantomTile) te );
|
||||
if( phantomTE.hasBoundPosition() )
|
||||
{
|
||||
TileEntity phantom = w.getTileEntity( phantomTE.getBoundPosition() );
|
||||
if( phantom instanceof MetaTileEntityHolder && !isGTCEblocked( phantom, s ) )
|
||||
{
|
||||
allAreBusy = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if( Loader.isModLoaded( "gregtech" ) && te instanceof MetaTileEntityHolder )
|
||||
{
|
||||
if( !isGTCEblocked( te, s ) )
|
||||
{
|
||||
allAreBusy = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( !invIsBlocked( ad ) )
|
||||
{
|
||||
allAreBusy = false;
|
||||
break;
|
||||
}
|
||||
|
||||
else if( !invIsBlocked( ad ) )
|
||||
{
|
||||
allAreBusy = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1062,6 +1211,12 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
return busy;
|
||||
}
|
||||
|
||||
boolean isGTCEblocked(TileEntity te, EnumFacing s)
|
||||
{
|
||||
GTad = GTCEInventoryAdaptor.getAdaptor( te, s.getOpposite() );
|
||||
return invIsBlockedGTCE( GTad );
|
||||
}
|
||||
|
||||
private boolean sameGrid( final IGrid grid ) throws GridAccessException
|
||||
{
|
||||
return grid == this.gridProxy.getGrid();
|
||||
@@ -1117,6 +1272,20 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
}
|
||||
}
|
||||
|
||||
if( this.waitingToSendFacing != null )
|
||||
{
|
||||
for (List<ItemStack> itemList : waitingToSendFacing.values())
|
||||
{
|
||||
for (final ItemStack is : itemList)
|
||||
{
|
||||
if (!is.isEmpty())
|
||||
{
|
||||
drops.add(is);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( final ItemStack is : this.upgrades )
|
||||
{
|
||||
if( !is.isEmpty() )
|
||||
|
||||
@@ -62,6 +62,7 @@ public class HighlighterHandler
|
||||
tessellator.draw();
|
||||
|
||||
GlStateManager.enableTexture2D();
|
||||
GlStateManager.enableDepth();
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
|
||||
@@ -43,5 +43,6 @@ public enum InventoryAction
|
||||
ROLL_UP,
|
||||
ROLL_DOWN,
|
||||
AUTO_CRAFT,
|
||||
PLACE_SINGLE
|
||||
PLACE_SINGLE,
|
||||
PLACE_JEI_GHOST_ITEM
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
package appeng.integration.modules.gregtech;
|
||||
|
||||
import appeng.util.inv.ItemSlot;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public abstract class GTCEInventoryAdaptor implements Iterable<ItemSlot>
|
||||
{
|
||||
public static GTCEInventoryAdaptor getAdaptor(final TileEntity te, final EnumFacing d)
|
||||
{
|
||||
if (te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d))
|
||||
{
|
||||
// Attempt getting an IItemHandler for the given side via caps
|
||||
IItemHandler itemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d);
|
||||
if (itemHandler != null)
|
||||
{
|
||||
return new GTCEItemHandler(itemHandler);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract boolean canRemoveAllExceptCircuits();
|
||||
}
|
||||
package appeng.integration.modules.gregtech;
|
||||
|
||||
import appeng.util.inv.ItemSlot;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public abstract class GTCEInventoryAdaptor implements Iterable<ItemSlot>
|
||||
{
|
||||
public static GTCEInventoryAdaptor getAdaptor(final TileEntity te, final EnumFacing d)
|
||||
{
|
||||
if (te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d))
|
||||
{
|
||||
// Attempt getting an IItemHandler for the given side via caps
|
||||
IItemHandler itemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d);
|
||||
if (itemHandler != null)
|
||||
{
|
||||
return new GTCEItemHandler(itemHandler);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract boolean canRemoveAllExceptCircuits();
|
||||
}
|
||||
@@ -1,57 +1,58 @@
|
||||
package appeng.integration.modules.gregtech;
|
||||
|
||||
import appeng.util.inv.ItemSlot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class GTCEItemHandler extends GTCEInventoryAdaptor
|
||||
{
|
||||
ArrayList<Integer> GTCElenses = new ArrayList<>(Arrays.asList(15085,15214,15092,15111,15113,15219,15218,15243,15244,15209,15117,15206,15216,15331,15212,15213,15154,15122,15157,15190,15247));
|
||||
ArrayList<Integer> GTCEmolds = new ArrayList<>(Arrays.asList(32301,32303,32304,32305,32306,32307,32308,32309,32313,32314,32315,32317,32350,32351,32352,32353,32354,32355,32356,32358,32359,32360,32361,32363,32364,32365,32366,32367,32368,32369,32370,32371,32372,32373));
|
||||
Item smallGearExtruderShape = Item.getByNameOrId("contenttweaker:smallgearextrudershape");
|
||||
Item creativePortableTankMold = Item.getByNameOrId("contenttweaker:creativeportabletankmold");
|
||||
|
||||
protected final IItemHandler itemHandler;
|
||||
|
||||
public GTCEItemHandler(IItemHandler itemHandler)
|
||||
{
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
|
||||
boolean isBlockableItem(ItemStack stack)
|
||||
{
|
||||
if ( stack.getItem() == Item.getByNameOrId("gregtech:meta_item_1") ) {
|
||||
int metadata = stack.getItemDamage();
|
||||
if ( metadata == 32766 || GTCElenses.contains(metadata) || GTCEmolds.contains(metadata)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( stack.getItem() == smallGearExtruderShape ) return false;
|
||||
if ( stack.getItem() == creativePortableTankMold) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRemoveAllExceptCircuits()
|
||||
{
|
||||
int slots = this.itemHandler.getSlots();
|
||||
for ( int slot = 0; slot < slots; slot++ ) {
|
||||
ItemStack is = this.itemHandler.getStackInSlot(slot);
|
||||
if ( is.isEmpty() || !isBlockableItem(is) ) continue;
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
package appeng.integration.modules.gregtech;
|
||||
|
||||
import appeng.util.inv.ItemHandlerIterator;
|
||||
import appeng.util.inv.ItemSlot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class GTCEItemHandler extends GTCEInventoryAdaptor
|
||||
{
|
||||
ArrayList<Integer> GTCElenses = new ArrayList<>(Arrays.asList(15085,15214,15092,15111,15113,15219,15218,15243,15244,15209,15117,15206,15216,15331,15212,15213,15154,15122,15157,15190,15247));
|
||||
ArrayList<Integer> GTCEmolds = new ArrayList<>(Arrays.asList(32301,32303,32304,32305,32306,32307,32308,32309,32313,32314,32315,32317,32350,32351,32352,32353,32354,32355,32356,32358,32359,32360,32361,32363,32364,32365,32366,32367,32368,32369,32370,32371,32372,32373));
|
||||
Item smallGearExtruderShape = Item.getByNameOrId("contenttweaker:smallgearextrudershape");
|
||||
Item creativePortableTankMold = Item.getByNameOrId("contenttweaker:creativeportabletankmold");
|
||||
|
||||
protected final IItemHandler itemHandler;
|
||||
|
||||
public GTCEItemHandler(IItemHandler itemHandler)
|
||||
{
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
|
||||
boolean isBlockableItem(ItemStack stack)
|
||||
{
|
||||
if ( stack.getItem() == Item.getByNameOrId("gregtech:meta_item_1") ) {
|
||||
int metadata = stack.getItemDamage();
|
||||
if ( metadata == 32766 || GTCElenses.contains(metadata) || GTCEmolds.contains(metadata)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( stack.getItem() == smallGearExtruderShape ) return false;
|
||||
if ( stack.getItem() == creativePortableTankMold) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRemoveAllExceptCircuits()
|
||||
{
|
||||
int slots = this.itemHandler.getSlots();
|
||||
for ( int slot = 0; slot < slots; slot++ ) {
|
||||
ItemStack is = this.itemHandler.getStackInSlot(slot);
|
||||
if ( is.isEmpty() || !isBlockableItem(is) ) continue;
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new ItemHandlerIterator( this.itemHandler );
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,8 @@
|
||||
package appeng.integration.modules.jei;
|
||||
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -27,14 +29,11 @@ import appeng.client.gui.AEGuiHandler;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import mezz.jei.api.*;
|
||||
import mezz.jei.config.Constants;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import mezz.jei.api.IJeiRuntime;
|
||||
import mezz.jei.api.IModPlugin;
|
||||
import mezz.jei.api.IModRegistry;
|
||||
import mezz.jei.api.ISubtypeRegistry;
|
||||
import mezz.jei.api.recipe.IRecipeCategoryRegistration;
|
||||
import mezz.jei.api.recipe.VanillaRecipeCategoryUid;
|
||||
|
||||
@@ -57,6 +56,9 @@ import appeng.items.parts.ItemFacade;
|
||||
@mezz.jei.api.JEIPlugin
|
||||
public class JEIPlugin implements IModPlugin
|
||||
{
|
||||
public static IJeiRuntime runtime;
|
||||
public static AEGuiHandler aeGuiHandler;
|
||||
|
||||
@Override
|
||||
public void registerItemSubtypes( ISubtypeRegistry subtypeRegistry )
|
||||
{
|
||||
@@ -95,8 +97,9 @@ public class JEIPlugin implements IModPlugin
|
||||
.addRecipeTransferHandler( new RecipeTransferHandler<>( ContainerPatternTerm.class ),
|
||||
Constants.UNIVERSAL_RECIPE_TRANSFER_UID );
|
||||
|
||||
AEGuiHandler aeGuiHandler = new AEGuiHandler();
|
||||
aeGuiHandler = new AEGuiHandler();
|
||||
registry.addAdvancedGuiHandlers(aeGuiHandler);
|
||||
registry.addGhostIngredientHandler( aeGuiHandler.getGuiContainerClass(), aeGuiHandler);
|
||||
}
|
||||
|
||||
private void registerDescriptions( IDefinitions definitions, IModRegistry registry )
|
||||
@@ -219,5 +222,6 @@ public class JEIPlugin implements IModPlugin
|
||||
{
|
||||
JEIModule jeiModule = (JEIModule) Integrations.jei();
|
||||
jeiModule.setJei( new JeiRuntimeAdapter( jeiRuntime ) );
|
||||
runtime = jeiRuntime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.Map;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.container.implementations.ContainerPatternTerm;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
import mezz.jei.api.recipe.VanillaRecipeCategoryUid;
|
||||
import mezz.jei.transfer.RecipeTransferErrorInternal;
|
||||
import mezz.jei.transfer.RecipeTransferErrorTooltip;
|
||||
@@ -73,24 +74,7 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
|
||||
{
|
||||
final String recipeType = recipeLayout.getRecipeCategory().getUid();
|
||||
|
||||
if (!recipeType.equals( VanillaRecipeCategoryUid.INFORMATION) && !recipeType.equals(VanillaRecipeCategoryUid.FUEL))
|
||||
{
|
||||
if( container instanceof ContainerPatternTerm )
|
||||
{
|
||||
if( !( (ContainerPatternTerm) container ).isCraftingMode() )
|
||||
{
|
||||
if( recipeType.equals( VanillaRecipeCategoryUid.CRAFTING ) )
|
||||
{
|
||||
return new RecipeTransferErrorTooltip( I18n.format( "gui.appliedenergistics2.CraftingPattern" ) );
|
||||
}
|
||||
}
|
||||
else if( !recipeType.equals( VanillaRecipeCategoryUid.CRAFTING ) )
|
||||
{
|
||||
return new RecipeTransferErrorTooltip( I18n.format( "gui.appliedenergistics2.ProcessingPattern" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if (recipeType.equals( VanillaRecipeCategoryUid.INFORMATION) || recipeType.equals(VanillaRecipeCategoryUid.FUEL))
|
||||
{
|
||||
return RecipeTransferErrorInternal.INSTANCE;
|
||||
}
|
||||
@@ -100,6 +84,30 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
|
||||
return null;
|
||||
}
|
||||
|
||||
if( container instanceof ContainerPatternTerm )
|
||||
{
|
||||
try
|
||||
{
|
||||
if( !( (ContainerPatternTerm) container ).isCraftingMode() )
|
||||
{
|
||||
if( recipeType.equals( VanillaRecipeCategoryUid.CRAFTING ) )
|
||||
{
|
||||
NetworkHandler.instance().sendToServer( new PacketValueConfig( "PatternTerminal.CraftMode", "1" ) );
|
||||
}
|
||||
}
|
||||
else if( !recipeType.equals( VanillaRecipeCategoryUid.CRAFTING ) )
|
||||
{
|
||||
|
||||
NetworkHandler.instance().sendToServer( new PacketValueConfig( "PatternTerminal.CraftMode", "0" ) );
|
||||
}
|
||||
|
||||
}
|
||||
catch( IOException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Map<Integer, ? extends IGuiIngredient<ItemStack>> ingredients = recipeLayout.getItemStacks().getGuiIngredients();
|
||||
|
||||
final NBTTagCompound recipe = new NBTTagCompound();
|
||||
|
||||
@@ -633,10 +633,10 @@ public class GridNode implements IGridNode, IPathItem
|
||||
this.usedChannels = 0;
|
||||
}
|
||||
|
||||
final int idx = this.connections.indexOf( fast );
|
||||
final int idx = this.connections.indexOf( (IGridConnection) fast );
|
||||
if( idx > 0 )
|
||||
{
|
||||
this.connections.remove( fast );
|
||||
this.connections.remove( (IGridConnection) fast );
|
||||
this.connections.add( 0, (IGridConnection) fast );
|
||||
}
|
||||
}
|
||||
|
||||
+18
-10
@@ -42,6 +42,10 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectRBTreeSet;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectSet;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
@@ -105,8 +109,8 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
||||
private final Set<ICraftingProvider> craftingProviders = new HashSet<>();
|
||||
private final Map<IGridNode, ICraftingWatcher> craftingWatchers = new HashMap<>();
|
||||
private final IGrid grid;
|
||||
private final Map<ICraftingPatternDetails, List<ICraftingMedium>> craftingMethods = new HashMap<>();
|
||||
private final Map<IAEItemStack, ImmutableList<ICraftingPatternDetails>> craftableItems = new HashMap<>();
|
||||
private final Object2ObjectMap<ICraftingPatternDetails, List<ICraftingMedium>> craftingMethods = new Object2ObjectOpenHashMap<>();
|
||||
private final Object2ObjectMap<IAEItemStack, ImmutableList<ICraftingPatternDetails>> craftableItems = new Object2ObjectOpenHashMap<>();
|
||||
private final Set<IAEItemStack> emitableItems = new HashSet<>();
|
||||
private final Map<String, CraftingLinkNexus> craftingLinks = new HashMap<>();
|
||||
private final Multimap<IAEStack, CraftingWatcher> interests = HashMultimap.create();
|
||||
@@ -160,11 +164,11 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
||||
{
|
||||
if( machine instanceof ICraftingWatcherHost )
|
||||
{
|
||||
final ICraftingWatcher craftingWatcher = this.craftingWatchers.get( machine );
|
||||
final ICraftingWatcher craftingWatcher = this.craftingWatchers.get( gridNode );
|
||||
if( craftingWatcher != null )
|
||||
{
|
||||
craftingWatcher.reset();
|
||||
this.craftingWatchers.remove( machine );
|
||||
this.craftingWatchers.remove( gridNode );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,7 +274,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
||||
return;
|
||||
}
|
||||
|
||||
final Map<IAEItemStack, ImmutableList<ICraftingPatternDetails>> oldItems = this.craftableItems;
|
||||
final Object2ObjectMap<IAEItemStack, ImmutableList<ICraftingPatternDetails>> oldItems = this.craftableItems;
|
||||
|
||||
// erase list.
|
||||
this.craftingMethods.clear();
|
||||
@@ -287,7 +291,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
||||
provider.provideCrafting( this );
|
||||
}
|
||||
|
||||
final Map<IAEItemStack, Set<ICraftingPatternDetails>> tmpCraft = new HashMap<>();
|
||||
final Object2ObjectMap<IAEItemStack, ObjectSet<ICraftingPatternDetails>> tmpCraft = new Object2ObjectOpenHashMap<>();
|
||||
|
||||
// new craftables!
|
||||
for( final ICraftingPatternDetails details : this.craftingMethods.keySet() )
|
||||
@@ -298,11 +302,11 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
||||
out.reset();
|
||||
out.setCraftable( true );
|
||||
|
||||
Set<ICraftingPatternDetails> methods = tmpCraft.get( out );
|
||||
ObjectSet<ICraftingPatternDetails> methods = tmpCraft.get( out );
|
||||
|
||||
if( methods == null )
|
||||
{
|
||||
tmpCraft.put( out, methods = new TreeSet<>( COMPARATOR ) );
|
||||
tmpCraft.put( out, methods = new ObjectRBTreeSet<>( COMPARATOR ) );
|
||||
}
|
||||
|
||||
methods.add( details );
|
||||
@@ -310,7 +314,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
||||
}
|
||||
|
||||
// make them immutable
|
||||
for( final Entry<IAEItemStack, Set<ICraftingPatternDetails>> e : tmpCraft.entrySet() )
|
||||
for( final Entry<IAEItemStack, ObjectSet<ICraftingPatternDetails>> e : tmpCraft.entrySet() )
|
||||
{
|
||||
this.craftableItems.put( e.getKey(), ImmutableList.copyOf( e.getValue() ) );
|
||||
}
|
||||
@@ -635,7 +639,11 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
||||
|
||||
public boolean hasCpu( final ICraftingCPU cpu )
|
||||
{
|
||||
return this.craftingCPUClusters.contains( cpu );
|
||||
if (cpu instanceof CraftingCPUCluster)
|
||||
{
|
||||
return this.craftingCPUClusters.contains( (CraftingCPUCluster) cpu );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public GenericInterestManager<CraftingWatcher> getInterestManager()
|
||||
|
||||
+153
-24
@@ -30,6 +30,7 @@ import java.util.PriorityQueue;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.HashMultiset;
|
||||
import com.google.common.collect.Multiset;
|
||||
import com.google.common.collect.Sets;
|
||||
@@ -63,7 +64,7 @@ import appeng.me.energy.EnergyWatcher;
|
||||
public class EnergyGridCache implements IEnergyGrid
|
||||
{
|
||||
|
||||
private static final double MAX_BUFFER_STORAGE = 200;
|
||||
private static final double MAX_BUFFER_STORAGE = 800;
|
||||
private static final Comparator<IEnergyGridProvider> COMPARATOR_HIGHEST_AMOUNT_STORED_FIRST = ( o1, o2 ) -> Double.compare( o2.getProviderStoredEnergy(),
|
||||
o1.getProviderStoredEnergy() );
|
||||
|
||||
@@ -76,9 +77,24 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
};
|
||||
|
||||
private final NavigableSet<EnergyThreshold> interests = Sets.newTreeSet();
|
||||
|
||||
// Should only be modified from the add/remove methods below to guard against
|
||||
// concurrent modifications
|
||||
private final double averageLength = 40.0;
|
||||
private final Set<IAEPowerStorage> providers = new LinkedHashSet<>();
|
||||
// Used to track whether an extraction is currently in progress, to fail fast
|
||||
// when something externally
|
||||
// modifies the energy grid.
|
||||
private boolean ongoingExtractOperation = false;
|
||||
|
||||
// Should only be modified from the add/remove methods below to guard against
|
||||
// concurrent modifications
|
||||
private final Set<IAEPowerStorage> requesters = new LinkedHashSet<>();
|
||||
// Used to track whether an injection is currently in progress, to fail fast
|
||||
// when something externally
|
||||
// modifies the energy grid.
|
||||
private boolean ongoingInjectOperation = false;
|
||||
|
||||
private final Multiset<IEnergyGridProvider> energyGridProviders = HashMultiset.create();
|
||||
private final IGrid myGrid;
|
||||
private final HashMap<IGridNode, IEnergyWatcher> watchers = new HashMap<>();
|
||||
@@ -110,6 +126,10 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
private double lastStoredPower = -1;
|
||||
|
||||
private final GridPowerStorage localStorage = new GridPowerStorage();
|
||||
private Set<IAEPowerStorage> providerToRemove = new HashSet<>();
|
||||
private Set<IAEPowerStorage> requesterToRemove = new HashSet<>();
|
||||
private Set<IAEPowerStorage> providersToAdd = new HashSet<>();
|
||||
private Set<IAEPowerStorage> requesterToAdd = new HashSet<>();
|
||||
|
||||
public EnergyGridCache( final IGrid g )
|
||||
{
|
||||
@@ -143,18 +163,32 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
{
|
||||
if( ev.storage.isAEPublicPowerStorage() )
|
||||
{
|
||||
switch( ev.type )
|
||||
switch ( ev.type )
|
||||
{
|
||||
case PROVIDE_POWER:
|
||||
if( ev.storage.getPowerFlow() != AccessRestriction.WRITE )
|
||||
{
|
||||
this.providers.add( ev.storage );
|
||||
if( !ongoingExtractOperation )
|
||||
{
|
||||
addProvider( ev.storage );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.providersToAdd.add( ev.storage );
|
||||
}
|
||||
}
|
||||
break;
|
||||
case REQUEST_POWER:
|
||||
if( ev.storage.getPowerFlow() != AccessRestriction.READ )
|
||||
{
|
||||
this.requesters.add( ev.storage );
|
||||
if( !ongoingInjectOperation )
|
||||
{
|
||||
addRequester( ev.storage );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.requesterToAdd.add( ev.storage );
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -168,6 +202,23 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
@Override
|
||||
public void onUpdateTick()
|
||||
{
|
||||
if (!providerToRemove.isEmpty() && !ongoingExtractOperation) {
|
||||
this.providers.removeIf( p -> providerToRemove.contains( p ) );
|
||||
providerToRemove.clear();
|
||||
}
|
||||
if (!requesterToRemove.isEmpty() && !ongoingInjectOperation) {
|
||||
this.requesters.removeIf( r -> providerToRemove.contains( r ) );
|
||||
requesterToRemove.clear();
|
||||
}
|
||||
if (!providersToAdd.isEmpty() && !ongoingExtractOperation) {
|
||||
this.providers.addAll(providersToAdd);
|
||||
providersToAdd.clear();
|
||||
}
|
||||
if( !requesterToAdd.isEmpty() && !ongoingInjectOperation){
|
||||
this.requesters.addAll(requesterToAdd);
|
||||
requesterToAdd.clear();
|
||||
}
|
||||
|
||||
if( !this.interests.isEmpty() )
|
||||
{
|
||||
final double oldPower = this.lastStoredPower;
|
||||
@@ -303,18 +354,30 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
|
||||
final Iterator<IAEPowerStorage> it = this.providers.iterator();
|
||||
|
||||
while( extractedPower < amt && it.hasNext() )
|
||||
ongoingExtractOperation = true;
|
||||
try
|
||||
{
|
||||
final IAEPowerStorage node = it.next();
|
||||
|
||||
final double req = amt - extractedPower;
|
||||
final double newPower = node.extractAEPower( req, mode, PowerMultiplier.ONE );
|
||||
extractedPower += newPower;
|
||||
|
||||
if( newPower < req && mode == Actionable.MODULATE )
|
||||
while ( extractedPower < amt && it.hasNext() )
|
||||
{
|
||||
it.remove();
|
||||
final IAEPowerStorage node = it.next();
|
||||
|
||||
if ( providerToRemove.contains( node )) {
|
||||
it.remove();
|
||||
providerToRemove.remove( node );
|
||||
continue;
|
||||
}
|
||||
|
||||
final double req = amt - extractedPower;
|
||||
final double newPower = node.extractAEPower( req, mode, PowerMultiplier.ONE );
|
||||
extractedPower += newPower;
|
||||
|
||||
if( newPower < req && mode == Actionable.MODULATE )
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
ongoingExtractOperation = false;
|
||||
}
|
||||
|
||||
final double result = Math.min( extractedPower, amt );
|
||||
@@ -340,15 +403,29 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
|
||||
final Iterator<IAEPowerStorage> it = this.requesters.iterator();
|
||||
|
||||
while( amt > 0 && it.hasNext() )
|
||||
ongoingInjectOperation = true;
|
||||
try
|
||||
{
|
||||
final IAEPowerStorage node = it.next();
|
||||
amt = node.injectAEPower( amt, mode );
|
||||
|
||||
if( amt > 0 && mode == Actionable.MODULATE )
|
||||
while ( amt > 0 && it.hasNext() )
|
||||
{
|
||||
it.remove();
|
||||
final IAEPowerStorage node = it.next();
|
||||
|
||||
if ( requesterToRemove.contains( node )) {
|
||||
it.remove();
|
||||
requesterToRemove.remove( node );
|
||||
continue;
|
||||
}
|
||||
|
||||
amt = node.injectAEPower( amt, mode );
|
||||
|
||||
if( amt > 0 && mode == Actionable.MODULATE )
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
} finally
|
||||
{
|
||||
ongoingInjectOperation = false;
|
||||
}
|
||||
|
||||
final double overflow = Math.max( 0.0, amt );
|
||||
@@ -505,9 +582,22 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
this.globalMaxPower -= ps.getAEMaxPower();
|
||||
this.globalAvailablePower -= ps.getAECurrentPower();
|
||||
}
|
||||
|
||||
this.providers.remove( ps );
|
||||
this.requesters.remove( ps );
|
||||
if( !ongoingExtractOperation )
|
||||
{
|
||||
removeProvider( ps );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.providerToRemove.add( ps );
|
||||
}
|
||||
if( !ongoingInjectOperation )
|
||||
{
|
||||
removeRequester( ps );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.requesterToRemove.add( ps );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -523,6 +613,31 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
}
|
||||
}
|
||||
|
||||
private void addRequester(IAEPowerStorage requester) {
|
||||
Preconditions.checkState(!ongoingInjectOperation,
|
||||
"Cannot modify energy requesters while energy is being injected.");
|
||||
this.requesters.add(requester);
|
||||
}
|
||||
|
||||
private void removeRequester(IAEPowerStorage requester) {
|
||||
Preconditions.checkState(!ongoingInjectOperation,
|
||||
"Cannot modify energy requesters while energy is being injected.");
|
||||
this.requesters.remove(requester);
|
||||
}
|
||||
|
||||
private void addProvider(IAEPowerStorage provider) {
|
||||
Preconditions.checkState(!ongoingExtractOperation,
|
||||
"Cannot modify energy providers while energy is being extracted.");
|
||||
this.providers.add(provider);
|
||||
}
|
||||
|
||||
private void removeProvider(IAEPowerStorage provider) {
|
||||
Preconditions.checkState(!ongoingExtractOperation,
|
||||
"Cannot modify energy providers while energy is being extracted.");
|
||||
this.providers.remove(provider);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addNode( final IGridNode node, final IGridHost machine )
|
||||
{
|
||||
@@ -554,12 +669,26 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
if( current > 0 && ps.getPowerFlow() != AccessRestriction.WRITE )
|
||||
{
|
||||
this.globalAvailablePower += current;
|
||||
this.providers.add( ps );
|
||||
if( !ongoingExtractOperation )
|
||||
{
|
||||
addProvider( ps );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.providersToAdd.add( ps );
|
||||
}
|
||||
}
|
||||
|
||||
if( current < max && ps.getPowerFlow() != AccessRestriction.READ )
|
||||
{
|
||||
this.requesters.add( ps );
|
||||
if( !ongoingInjectOperation )
|
||||
{
|
||||
addRequester( ps );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.requesterToAdd.add( ps );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -101,12 +101,12 @@ public class GridStorageCache implements IStorageGrid
|
||||
|
||||
if( machine instanceof IStackWatcherHost )
|
||||
{
|
||||
final IStackWatcher myWatcher = this.watchers.get( machine );
|
||||
final IStackWatcher myWatcher = this.watchers.get( node );
|
||||
|
||||
if( myWatcher != null )
|
||||
{
|
||||
myWatcher.reset();
|
||||
this.watchers.remove( machine );
|
||||
this.watchers.remove( node );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -44,6 +44,8 @@ import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.me.storage.ItemWatcher;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
|
||||
|
||||
public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
@@ -58,7 +60,7 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
@Nonnull
|
||||
private final IItemList<T> cachedList;
|
||||
@Nonnull
|
||||
private final Map<IMEMonitorHandlerReceiver<T>, Object> listeners;
|
||||
private final Object2ObjectMap<IMEMonitorHandlerReceiver<T>, Object> listeners;
|
||||
|
||||
private boolean sendEvent = false;
|
||||
private boolean hasChanged = false;
|
||||
@@ -70,7 +72,7 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
this.myGridCache = cache;
|
||||
this.myChannel = chan;
|
||||
this.cachedList = chan.createList();
|
||||
this.listeners = new HashMap<>();
|
||||
this.listeners = new Object2ObjectOpenHashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -314,7 +314,7 @@ public class PathGridCache implements IPathingGrid
|
||||
int depth = 0;
|
||||
for( final IGridNode nodes : this.requireChannels )
|
||||
{
|
||||
if( !this.semiOpen.contains( nodes ) )
|
||||
if( !this.semiOpen.contains( (IPathItem) nodes ) )
|
||||
{
|
||||
final IGridBlock gb = nodes.getGridBlock();
|
||||
final EnumSet<GridFlags> flags = gb.getFlags();
|
||||
|
||||
@@ -19,14 +19,11 @@
|
||||
package appeng.me.cluster.implementations;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
@@ -34,8 +31,6 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
@@ -93,6 +88,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||
private final List<TileCraftingTile> storage = new ArrayList<>();
|
||||
private final List<TileCraftingMonitorTile> status = new ArrayList<>();
|
||||
private final HashMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new HashMap<>();
|
||||
private final Map<ICraftingPatternDetails, Queue<ICraftingMedium>> visitedMediums = new HashMap<>();
|
||||
private ICraftingLink myLastLink;
|
||||
private String myName = "";
|
||||
private boolean isDestroyed = false;
|
||||
@@ -238,8 +234,9 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||
|
||||
public IAEItemStack injectItems( final IAEItemStack input, final Actionable type, final IActionSource src )
|
||||
{
|
||||
if( !( input instanceof IAEItemStack ) )
|
||||
{
|
||||
// also stop accepting items when the job is complete, i.e. to prevent re-insertion when pushing out
|
||||
// items during storeItems
|
||||
if (input == null || isComplete) {
|
||||
return input;
|
||||
}
|
||||
|
||||
@@ -297,7 +294,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||
{
|
||||
is.decStackSize( what.getStackSize() );
|
||||
|
||||
this.updateElapsedTime( what );
|
||||
this.updateRemainingItemCount( what );
|
||||
this.markDirty();
|
||||
this.postCraftingStatusChange( what.copy().setStackSize( -what.getStackSize() ) );
|
||||
|
||||
@@ -436,6 +433,11 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||
AELog.crafting( LOG_MARK_AS_COMPLETE, logStack );
|
||||
}
|
||||
|
||||
// Waiting for can potentially contain items at this point, if the user has a 64xplank->64xbutton processing
|
||||
// recipe for example, but only requested 1xbutton. We just ignore the rest since it will be dumped
|
||||
// back into the network inventory regardless. For this to work it's important that injectItems in this CPU
|
||||
// does not accept any further items if isComplete is true.
|
||||
this.waitingFor.resetStatus();
|
||||
this.remainingItemCount = 0;
|
||||
this.startItemCount = 0;
|
||||
this.lastTime = 0;
|
||||
@@ -646,14 +648,22 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||
{
|
||||
InventoryCrafting ic = null;
|
||||
|
||||
for( final ICraftingMedium m : cc.getMediums( e.getKey() ) )
|
||||
if (!visitedMediums.containsKey( details ) || visitedMediums.get( details ).isEmpty())
|
||||
{
|
||||
visitedMediums.put( details, new ArrayDeque<>( cc.getMediums( details ).stream().filter( Objects::nonNull ).collect( Collectors.toList()) ) );
|
||||
}
|
||||
|
||||
while (!visitedMediums.get( details ).isEmpty())
|
||||
{
|
||||
|
||||
ICraftingMedium m = visitedMediums.get( details ).poll();
|
||||
|
||||
if( e.getValue().value <= 0 )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if( !m.isBusy() )
|
||||
if( m != null && !m.isBusy() )
|
||||
{
|
||||
if( ic == null )
|
||||
{
|
||||
@@ -825,6 +835,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||
|
||||
private void storeItems()
|
||||
{
|
||||
Preconditions.checkState(isComplete, "CPU should be complete to prevent re-insertion when dumping items");
|
||||
final IGrid g = this.getGrid();
|
||||
|
||||
if( g == null )
|
||||
@@ -835,23 +846,24 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||
final IStorageGrid sg = g.getCache( IStorageGrid.class );
|
||||
final IMEInventory<IAEItemStack> ii = sg.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) );
|
||||
|
||||
for( IAEItemStack is : this.inventory.getItemList() )
|
||||
IItemList<IAEItemStack> itemList = this.inventory.getItemList();
|
||||
for( IAEItemStack is : itemList )
|
||||
{
|
||||
is = this.inventory.extractItems( is.copy(), Actionable.MODULATE, this.machineSrc );
|
||||
this.postChange( is, this.machineSrc );
|
||||
IAEItemStack remainder = ii.injectItems( is.copy(), Actionable.MODULATE, this.machineSrc );
|
||||
|
||||
if( is != null )
|
||||
// The network was unable to receive all of the items, i.e. no or not enough storage space left
|
||||
if( remainder != null )
|
||||
{
|
||||
this.postChange( is, this.machineSrc );
|
||||
is = ii.injectItems( is, Actionable.MODULATE, this.machineSrc );
|
||||
is.setStackSize( remainder.getStackSize() );
|
||||
}
|
||||
|
||||
if( is != null )
|
||||
else
|
||||
{
|
||||
this.inventory.injectItems( is, Actionable.MODULATE, this.machineSrc );
|
||||
is.reset();
|
||||
}
|
||||
}
|
||||
|
||||
if( this.inventory.getItemList().isEmpty() )
|
||||
if( itemList.isEmpty() )
|
||||
{
|
||||
this.inventory = new MECraftingInventory();
|
||||
}
|
||||
@@ -936,14 +948,13 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||
@Override
|
||||
public boolean isBusy()
|
||||
{
|
||||
final Iterator<Entry<ICraftingPatternDetails, TaskProgress>> i = this.tasks.entrySet().iterator();
|
||||
|
||||
while( i.hasNext() )
|
||||
this.tasks.entrySet().removeIf(
|
||||
taskProgressEntry -> taskProgressEntry.getValue().value <= 0 );
|
||||
|
||||
if( !this.waitingFor.isEmpty() || !this.tasks.isEmpty() )
|
||||
{
|
||||
if( i.next().getValue().value <= 0 )
|
||||
{
|
||||
i.remove();
|
||||
}
|
||||
this.updateElapsedTime();
|
||||
}
|
||||
|
||||
return !this.tasks.isEmpty() || !this.waitingFor.isEmpty();
|
||||
@@ -1335,12 +1346,16 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||
this.remainingItemCount = itemCount;
|
||||
}
|
||||
|
||||
private void updateElapsedTime( final IAEItemStack is )
|
||||
private void updateRemainingItemCount( final IAEItemStack is )
|
||||
{
|
||||
this.remainingItemCount = this.getRemainingItemCount() - is.getStackSize();
|
||||
}
|
||||
|
||||
private void updateElapsedTime()
|
||||
{
|
||||
final long nextStartTime = System.nanoTime();
|
||||
this.elapsedTime = this.getElapsedTime() + nextStartTime - this.lastTime;
|
||||
this.lastTime = nextStartTime;
|
||||
this.remainingItemCount = this.getRemainingItemCount() - is.getStackSize();
|
||||
}
|
||||
|
||||
public long getElapsedTime()
|
||||
|
||||
@@ -277,6 +277,7 @@ public class BasicCellInventory<T extends IAEStack<T>> extends AbstractCellInven
|
||||
}
|
||||
|
||||
t.setStackSize( stackSize );
|
||||
t.setCraftable( false );
|
||||
|
||||
if( stackSize > 0 )
|
||||
{
|
||||
|
||||
@@ -218,6 +218,12 @@ public class PartImportBus extends PartSharedItemBus implements IInventoryDestin
|
||||
private boolean importStuff( final InventoryAdaptor myAdaptor, final IAEItemStack whatToImport, final IMEMonitor<IAEItemStack> inv, final IEnergySource energy, final FuzzyMode fzMode )
|
||||
{
|
||||
final int toSend = this.calculateMaximumAmountToImport( myAdaptor, whatToImport, inv, fzMode );
|
||||
|
||||
if( toSend == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
final ItemStack newItems;
|
||||
|
||||
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
@@ -286,8 +292,17 @@ public class PartImportBus extends PartSharedItemBus implements IInventoryDestin
|
||||
itemAmountNotStorable = inv.injectItems( AEItemStack.fromItemStack( simResult ), Actionable.SIMULATE, this.source );
|
||||
}
|
||||
|
||||
if( simResult.isEmpty() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( itemAmountNotStorable != null )
|
||||
{
|
||||
if( simResult.getCount() == itemAmountNotStorable.getStackSize() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return (int) Math.min( simResult.getCount() - itemAmountNotStorable.getStackSize(), toSend );
|
||||
}
|
||||
|
||||
|
||||
@@ -19,20 +19,10 @@
|
||||
package appeng.parts.misc;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.StorageFilter;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.StorageFilter;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.networking.storage.IBaseMonitor;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
@@ -46,7 +36,19 @@ import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.IGridProxyable;
|
||||
import appeng.me.storage.ITickingMonitor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.ItemHandlerIterator;
|
||||
import appeng.util.inv.ItemSlot;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
@@ -54,7 +56,7 @@ import appeng.util.item.AEItemStack;
|
||||
*/
|
||||
class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAEItemStack>, ITickingMonitor
|
||||
{
|
||||
private final Map<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new HashMap<>();
|
||||
private final Object2ObjectMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new Object2ObjectOpenHashMap<>();
|
||||
private IActionSource mySource;
|
||||
private final IItemHandler itemHandler;
|
||||
private final IGridProxyable proxyable;
|
||||
@@ -76,6 +78,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
@Override
|
||||
public IAEItemStack injectItems( IAEItemStack iox, Actionable type, IActionSource src )
|
||||
{
|
||||
|
||||
ItemStack orgInput = iox.createItemStack();
|
||||
ItemStack remaining = orgInput;
|
||||
|
||||
@@ -86,6 +89,10 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
for( int i = 0; i < slotCount && !remaining.isEmpty(); i++ )
|
||||
{
|
||||
remaining = this.itemHandler.insertItem( i, remaining, simulate );
|
||||
if( remaining.isEmpty() )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// At this point, we still have some items left...
|
||||
@@ -105,6 +112,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
{
|
||||
// meh
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return AEItemStack.fromItemStack( remaining );
|
||||
@@ -113,7 +121,6 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
@Override
|
||||
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, IActionSource src )
|
||||
{
|
||||
|
||||
ItemStack requestedItemStack = request.createItemStack();
|
||||
int remainingSize = requestedItemStack.getCount();
|
||||
|
||||
@@ -140,16 +147,9 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
do
|
||||
{
|
||||
extracted = this.itemHandler.extractItem( i, remainingCurrentSlot, simulate );
|
||||
|
||||
if( !extracted.isEmpty() )
|
||||
{
|
||||
// In order to guard against broken IItemHandler implementations, we'll try to guess if the returned
|
||||
// stack (especially in simulate mode) is the same that was returned by getStackInSlot. This is
|
||||
// obviously not a precise science, but it would catch the previous Forge bug:
|
||||
// https://github.com/MinecraftForge/MinecraftForge/pull/6580
|
||||
if (extracted == stackInInventorySlot) {
|
||||
extracted = extracted.copy();
|
||||
}
|
||||
|
||||
if( extracted.getCount() > remainingCurrentSlot )
|
||||
{
|
||||
// Something broke. It should never return more than we requested...
|
||||
@@ -159,17 +159,12 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
extracted.setCount( remainingCurrentSlot );
|
||||
}
|
||||
|
||||
// Heuristic for simulation: looping in case of simulations is pointless, since the state of the
|
||||
// underlying inventory does not change after a simulated extraction. To still support inventories
|
||||
// that report stacks that are larger than maxStackSize, we use this heuristic
|
||||
if (simulate && extracted.getCount() == extracted.getMaxStackSize()
|
||||
&& remainingCurrentSlot > extracted.getMaxStackSize()) {
|
||||
extracted.setCount(remainingCurrentSlot);
|
||||
}
|
||||
|
||||
// We're just gonna use the first stack we get our hands on as the template for the rest.
|
||||
// In case some stupid itemhandler (aka forge) returns an internal state we have to do a second
|
||||
// expensive copy again.
|
||||
if( gathered.isEmpty() )
|
||||
{
|
||||
gathered = extracted;
|
||||
gathered = extracted.copy();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -177,8 +172,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
}
|
||||
remainingCurrentSlot -= extracted.getCount();
|
||||
}
|
||||
}
|
||||
while( !simulate && !extracted.isEmpty() && remainingCurrentSlot > 0 );
|
||||
} while ( !extracted.isEmpty() && remainingCurrentSlot > 0 );
|
||||
|
||||
remainingSize -= stackSizeCurrentSlot - remainingCurrentSlot;
|
||||
|
||||
@@ -257,7 +251,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
private void postDifference( Iterable<IAEItemStack> a )
|
||||
{
|
||||
final Iterator<Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object>> i = this.listeners.entrySet().iterator();
|
||||
while( i.hasNext() )
|
||||
while ( i.hasNext() )
|
||||
{
|
||||
final Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object> l = i.next();
|
||||
final IMEMonitorHandlerReceiver<IAEItemStack> key = l.getKey();
|
||||
@@ -272,9 +266,9 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
}
|
||||
}
|
||||
|
||||
private static class InventoryCache
|
||||
private static class InventoryCache implements Iterable<ItemSlot>
|
||||
{
|
||||
private IAEItemStack[] cachedAeStacks = new IAEItemStack[0];
|
||||
private IItemList<IAEItemStack> cachedAeStacks = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
private final IItemHandler itemHandler;
|
||||
private final StorageFilter mode;
|
||||
|
||||
@@ -286,106 +280,77 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
|
||||
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
|
||||
{
|
||||
Arrays.stream( this.cachedAeStacks ).forEach( out::add );
|
||||
this.cachedAeStacks.forEach( out::add );
|
||||
return out;
|
||||
}
|
||||
|
||||
private StorageFilter getMode()
|
||||
{
|
||||
return this.mode;
|
||||
}
|
||||
|
||||
public List<IAEItemStack> update()
|
||||
{
|
||||
final List<IAEItemStack> changes = new ArrayList<>();
|
||||
final int slots = this.itemHandler.getSlots();
|
||||
|
||||
// Make room for new slots
|
||||
if( slots > this.cachedAeStacks.length )
|
||||
IItemList<IAEItemStack> storage = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
|
||||
for( final ItemSlot is : this )
|
||||
{
|
||||
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, slots );
|
||||
final ItemStack stackInSlot = !is.isExtractable() && this.getMode() == StorageFilter.EXTRACTABLE_ONLY ? ItemStack.EMPTY : is.getItemStack();
|
||||
if( !stackInSlot.isEmpty() )
|
||||
{
|
||||
storage.add( AEItemStack.fromItemStack( stackInSlot ) );
|
||||
}
|
||||
}
|
||||
|
||||
for( int slot = 0; slot < slots; slot++ )
|
||||
Iterator<IAEItemStack> cachedAeStacksIterator = cachedAeStacks.iterator();
|
||||
while ( cachedAeStacksIterator.hasNext() )
|
||||
{
|
||||
// Save the old stuff
|
||||
final IAEItemStack oldAeIS = this.cachedAeStacks[slot];
|
||||
ItemStack newIS = this.itemHandler.getStackInSlot( slot );
|
||||
if( this.mode == StorageFilter.EXTRACTABLE_ONLY && !newIS.isEmpty() )
|
||||
IAEItemStack cachedStack = cachedAeStacksIterator.next();
|
||||
IAEItemStack storedStack = storage.findPrecise( cachedStack );
|
||||
if( storedStack == null )
|
||||
{
|
||||
if( this.itemHandler.extractItem( slot, 1, true ).isEmpty() )
|
||||
{
|
||||
newIS = ItemStack.EMPTY;
|
||||
}
|
||||
changes.add( cachedStack.setStackSize( -cachedStack.getStackSize() ) );
|
||||
}
|
||||
else if( cachedStack.getStackSize() != storedStack.getStackSize() )
|
||||
{
|
||||
handleStackSizeChanged( cachedStack, storedStack, changes );
|
||||
}
|
||||
this.handlePossibleSlotChanges( slot, oldAeIS, newIS, changes );
|
||||
}
|
||||
|
||||
// Handle cases where the number of slots actually is lower now than before
|
||||
if( slots < this.cachedAeStacks.length )
|
||||
for( IAEItemStack storedStack : storage )
|
||||
{
|
||||
for( int slot = slots; slot < this.cachedAeStacks.length; slot++ )
|
||||
if( cachedAeStacks.findPrecise( storedStack ) == null )
|
||||
{
|
||||
final IAEItemStack aeStack = this.cachedAeStacks[slot];
|
||||
|
||||
if( aeStack != null )
|
||||
{
|
||||
final IAEItemStack a = aeStack.copy();
|
||||
a.setStackSize( -a.getStackSize() );
|
||||
changes.add( a );
|
||||
}
|
||||
cachedAeStacks.add( storedStack );
|
||||
changes.add( storedStack.copy() );
|
||||
}
|
||||
|
||||
// Reduce the cache size
|
||||
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, slots );
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
private void handlePossibleSlotChanges( int slot, IAEItemStack oldAeIS, ItemStack newIS, List<IAEItemStack> changes )
|
||||
{
|
||||
if( oldAeIS != null && oldAeIS.isSameType( newIS ) )
|
||||
{
|
||||
this.handleStackSizeChanged( slot, oldAeIS, newIS, changes );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.handleItemChanged( slot, oldAeIS, newIS, changes );
|
||||
}
|
||||
}
|
||||
|
||||
private void handleStackSizeChanged( int slot, IAEItemStack oldAeIS, ItemStack newIS, List<IAEItemStack> changes )
|
||||
private void handleStackSizeChanged( IAEItemStack cachedStack, IAEItemStack storedStack, List<IAEItemStack> changes )
|
||||
{
|
||||
// Still the same item, but amount might have changed
|
||||
final long diff = newIS.getCount() - oldAeIS.getStackSize();
|
||||
final long diff = storedStack.getStackSize() - cachedStack.getStackSize();
|
||||
|
||||
if( diff != 0 )
|
||||
{
|
||||
final IAEItemStack stack = oldAeIS.copy();
|
||||
stack.setStackSize( newIS.getCount() );
|
||||
cachedStack.setStackSize( storedStack.getStackSize() );
|
||||
|
||||
this.cachedAeStacks[slot] = stack;
|
||||
|
||||
final IAEItemStack a = stack.copy();
|
||||
a.setStackSize( diff );
|
||||
changes.add( a );
|
||||
final IAEItemStack diffStack = cachedStack.copy();
|
||||
diffStack.setStackSize( diff );
|
||||
changes.add( diffStack );
|
||||
}
|
||||
}
|
||||
|
||||
private void handleItemChanged( int slot, IAEItemStack oldAeIS, ItemStack newIS, List<IAEItemStack> changes )
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
// Completely different item
|
||||
this.cachedAeStacks[slot] = AEItemStack.fromItemStack( newIS );
|
||||
|
||||
// If we had a stack previously in this slot, notify the network about its disappearance
|
||||
if( oldAeIS != null )
|
||||
{
|
||||
oldAeIS.setStackSize( -oldAeIS.getStackSize() );
|
||||
changes.add( oldAeIS );
|
||||
}
|
||||
|
||||
// Notify the network about the new stack. Note that this is null if newIS was null
|
||||
if( this.cachedAeStacks[slot] != null )
|
||||
{
|
||||
changes.add( this.cachedAeStacks[slot] );
|
||||
}
|
||||
return new ItemHandlerIterator( this.itemHandler );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
package appeng.parts.misc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
|
||||
import appeng.core.AELog;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.capabilities.IItemRepository;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
@@ -23,15 +7,24 @@ import appeng.api.networking.storage.IBaseMonitor;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.core.AELog;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.IGridProxyable;
|
||||
import appeng.me.storage.ITickingMonitor;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.capabilities.IItemRepository;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Wraps an Item Repository in such a way that it can be used as an IMEInventory for items.
|
||||
@@ -40,7 +33,7 @@ import javax.annotation.Nonnull;
|
||||
|
||||
class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAEItemStack>, ITickingMonitor
|
||||
{
|
||||
private final Map<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new HashMap<>();
|
||||
private final Object2ObjectMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new Object2ObjectOpenHashMap<>();
|
||||
private IActionSource mySource;
|
||||
private final IItemRepository itemRepository;
|
||||
private final IGridProxyable proxyable;
|
||||
@@ -90,13 +83,12 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
||||
@Override
|
||||
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, IActionSource src )
|
||||
{
|
||||
ItemStack requestedItemStack = request.createItemStack();
|
||||
int remainingSize = requestedItemStack.getCount();
|
||||
ItemStack requestedItemStack = request.getDefinition();
|
||||
int remainingSize = (int) Math.min( Integer.MAX_VALUE, request.getStackSize() );
|
||||
|
||||
final boolean simulate = ( mode == Actionable.SIMULATE );
|
||||
|
||||
ItemStack extracted;
|
||||
extracted = this.itemRepository.extractItem( requestedItemStack, remainingSize, simulate );
|
||||
ItemStack extracted = this.itemRepository.extractItem( requestedItemStack, remainingSize, simulate );
|
||||
|
||||
if( extracted.getCount() > remainingSize )
|
||||
{
|
||||
@@ -120,10 +112,8 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
||||
// meh
|
||||
}
|
||||
}
|
||||
|
||||
return AEItemStack.fromItemStack( extracted );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -154,7 +144,7 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
||||
private void postDifference( Iterable<IAEItemStack> a )
|
||||
{
|
||||
final Iterator<Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object>> i = this.listeners.entrySet().iterator();
|
||||
while( i.hasNext() )
|
||||
while ( i.hasNext() )
|
||||
{
|
||||
final Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object> l = i.next();
|
||||
final IMEMonitorHandlerReceiver<IAEItemStack> key = l.getKey();
|
||||
@@ -194,7 +184,7 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
||||
|
||||
private static class InventoryCache
|
||||
{
|
||||
private IAEItemStack[] cachedAeStacks = new IAEItemStack[0];
|
||||
private IItemList<IAEItemStack> cachedAeStacks = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
private final IItemRepository iItemRepository;
|
||||
|
||||
public InventoryCache( IItemRepository iItemRepository )
|
||||
@@ -204,7 +194,7 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
||||
|
||||
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
|
||||
{
|
||||
Arrays.stream( this.cachedAeStacks ).forEach( out::add );
|
||||
this.cachedAeStacks.forEach( out::add );
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -212,94 +202,51 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
||||
{
|
||||
final List<IAEItemStack> changes = new ArrayList<>();
|
||||
|
||||
List<IAEItemStack> out = this.iItemRepository.getAllItems().stream().map( s -> AEItemStack.fromItemStack( s.itemPrototype ).setStackSize( s.count ) ).collect(Collectors.toList() );
|
||||
IItemList<IAEItemStack> storage = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
this.iItemRepository.getAllItems().stream().map( s -> AEItemStack.fromItemStack( s.itemPrototype ).setStackSize( s.count ) ).forEach( storage::add );
|
||||
|
||||
final int size = out.size();
|
||||
|
||||
// Make room for new slots
|
||||
if( size > this.cachedAeStacks.length )
|
||||
Iterator<IAEItemStack> cachedAeStacksIterator = cachedAeStacks.iterator();
|
||||
while ( cachedAeStacksIterator.hasNext() )
|
||||
{
|
||||
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, size );
|
||||
}
|
||||
|
||||
for( int x = 0; x < size; x++ )
|
||||
{
|
||||
// Save the old stuff
|
||||
final IAEItemStack oldAeIS = this.cachedAeStacks[x];
|
||||
final IAEItemStack newIS = out.get( x );
|
||||
|
||||
this.handlePossibleSlotChanges( x, oldAeIS, newIS, changes );
|
||||
}
|
||||
|
||||
// Handle cases where the number of slots actually is lower now than before
|
||||
if( size < this.cachedAeStacks.length )
|
||||
{
|
||||
for( int x = 0; x < this.cachedAeStacks.length; x++ )
|
||||
IAEItemStack cachedStack = cachedAeStacksIterator.next();
|
||||
IAEItemStack storedStack = storage.findPrecise( cachedStack );
|
||||
if( storedStack == null )
|
||||
{
|
||||
final IAEItemStack aeStack = this.cachedAeStacks[x];
|
||||
|
||||
if( aeStack != null )
|
||||
{
|
||||
final IAEItemStack a = aeStack.copy();
|
||||
a.setStackSize( -a.getStackSize() );
|
||||
changes.add( a );
|
||||
}
|
||||
changes.add( cachedStack.setStackSize( -cachedStack.getStackSize() ) );
|
||||
cachedAeStacksIterator.remove();
|
||||
}
|
||||
else if( cachedStack.getStackSize() != storedStack.getStackSize() )
|
||||
{
|
||||
handleStackSizeChanged( cachedStack, storedStack, changes );
|
||||
}
|
||||
}
|
||||
|
||||
// Reduce the cache size
|
||||
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, size );
|
||||
for( IAEItemStack storedStack : storage )
|
||||
{
|
||||
if( cachedAeStacks.findPrecise( storedStack ) == null )
|
||||
{
|
||||
cachedAeStacks.add( storedStack );
|
||||
changes.add( storedStack.copy() );
|
||||
}
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
private void handlePossibleSlotChanges( int slot, IAEItemStack oldAeIS, IAEItemStack newIS, List<IAEItemStack> changes )
|
||||
{
|
||||
if( oldAeIS != null && oldAeIS.isSameType( newIS ) )
|
||||
{
|
||||
this.handleStackSizeChanged( slot, oldAeIS, newIS, changes );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.handleItemChanged( slot, oldAeIS, newIS, changes );
|
||||
}
|
||||
}
|
||||
|
||||
private void handleStackSizeChanged( int slot, IAEItemStack oldAeIS, IAEItemStack newIS, List<IAEItemStack> changes )
|
||||
private void handleStackSizeChanged( IAEItemStack cachedStack, IAEItemStack storedStack, List<IAEItemStack> changes )
|
||||
{
|
||||
// Still the same item, but amount might have changed
|
||||
final long diff = newIS.getStackSize() - oldAeIS.getStackSize();
|
||||
final long diff = storedStack.getStackSize() - cachedStack.getStackSize();
|
||||
|
||||
if( diff != 0 )
|
||||
{
|
||||
final IAEItemStack stack = oldAeIS.copy();
|
||||
stack.setStackSize( newIS.getStackSize() );
|
||||
cachedStack.setStackSize( storedStack.getStackSize() );
|
||||
|
||||
this.cachedAeStacks[slot] = stack;
|
||||
|
||||
final IAEItemStack a = stack.copy();
|
||||
a.setStackSize( diff );
|
||||
changes.add( a );
|
||||
final IAEItemStack diffStack = cachedStack.copy();
|
||||
diffStack.setStackSize( diff );
|
||||
changes.add( diffStack );
|
||||
}
|
||||
}
|
||||
|
||||
private void handleItemChanged( int slot, IAEItemStack oldAeIS, IAEItemStack newIS, List<IAEItemStack> changes )
|
||||
{
|
||||
// Completely different item
|
||||
this.cachedAeStacks[slot] = newIS ;
|
||||
|
||||
// If we had a stack previously in this slot, notify the network about its disappearance
|
||||
if( oldAeIS != null )
|
||||
{
|
||||
oldAeIS.setStackSize( -oldAeIS.getStackSize() );
|
||||
changes.add( oldAeIS );
|
||||
}
|
||||
|
||||
// Notify the network about the new stack. Note that this is null if newIS was null
|
||||
if( this.cachedAeStacks[slot] != null )
|
||||
{
|
||||
changes.add( this.cachedAeStacks[slot] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,19 +258,19 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
@Override
|
||||
public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource source )
|
||||
{
|
||||
try
|
||||
if( source == this.mySrc || source.machine().map( machine -> machine == this ).orElse( false ) )
|
||||
{
|
||||
if( this.getProxy().isActive() )
|
||||
try
|
||||
{
|
||||
this.getProxy()
|
||||
.getStorage()
|
||||
.postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), change,
|
||||
this.mySrc );
|
||||
if( this.getProxy().isActive() )
|
||||
{
|
||||
this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), change, this.mySrc );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :(
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :(
|
||||
}
|
||||
}
|
||||
|
||||
@@ -401,10 +401,13 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
}
|
||||
|
||||
// Check via cap for IItemRepository
|
||||
IItemRepository handlerRepo = target.getCapability( ITEM_REPOSITORY_CAPABILITY, targetSide );
|
||||
if( handlerRepo != null )
|
||||
if (ITEM_REPOSITORY_CAPABILITY != null && target.hasCapability( ITEM_REPOSITORY_CAPABILITY, targetSide ))
|
||||
{
|
||||
return new ItemRepositoryAdapter( handlerRepo, this );
|
||||
IItemRepository handlerRepo = target.getCapability( ITEM_REPOSITORY_CAPABILITY, targetSide );
|
||||
if( handlerRepo != null )
|
||||
{
|
||||
return new ItemRepositoryAdapter( handlerRepo, this );
|
||||
}
|
||||
}
|
||||
// Check via cap for IItemHandler
|
||||
IItemHandler handlerExt = target.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, targetSide );
|
||||
@@ -431,11 +434,14 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
return Objects.hash( target, target.getCapability( Capabilities.STORAGE_MONITORABLE_ACCESSOR, targetSide ) );
|
||||
}
|
||||
|
||||
final IItemRepository handlerRepo = target.getCapability( ITEM_REPOSITORY_CAPABILITY, targetSide );
|
||||
|
||||
if( handlerRepo != null )
|
||||
if (ITEM_REPOSITORY_CAPABILITY != null && target.hasCapability( ITEM_REPOSITORY_CAPABILITY, targetSide ))
|
||||
{
|
||||
return Objects.hash( target, handlerRepo, handlerRepo.getAllItems().size() );
|
||||
final IItemRepository handlerRepo = target.getCapability( ITEM_REPOSITORY_CAPABILITY, targetSide );
|
||||
|
||||
if( handlerRepo != null )
|
||||
{
|
||||
return Objects.hash( target, handlerRepo, handlerRepo.getAllItems().size() );
|
||||
}
|
||||
}
|
||||
|
||||
final IItemHandler itemHandler = target.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, targetSide );
|
||||
|
||||
@@ -19,11 +19,12 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.me.cache.helpers.TunnelCollection;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
@@ -42,6 +43,7 @@ public class PartP2PFEPower extends PartP2PTunnel<PartP2PFEPower>
|
||||
private static final IEnergyStorage NULL_ENERGY_STORAGE = new NullEnergyStorage();
|
||||
private final IEnergyStorage inputHandler = new InputEnergyStorage();
|
||||
private final IEnergyStorage outputHandler = new OutputEnergyStorage();
|
||||
private final Queue<PartP2PFEPower> outputs = new ArrayDeque<>();
|
||||
|
||||
public PartP2PFEPower( ItemStack is )
|
||||
{
|
||||
@@ -108,6 +110,8 @@ public class PartP2PFEPower extends PartP2PTunnel<PartP2PFEPower>
|
||||
|
||||
private class InputEnergyStorage implements IEnergyStorage
|
||||
{
|
||||
private boolean iteratingOutputs;
|
||||
|
||||
@Override
|
||||
public int extractEnergy( int maxExtract, boolean simulate )
|
||||
{
|
||||
@@ -131,8 +135,14 @@ public class PartP2PFEPower extends PartP2PTunnel<PartP2PFEPower>
|
||||
final int amountPerOutput = maxReceive / outputTunnels;
|
||||
int overflow = amountPerOutput == 0 ? maxReceive : maxReceive % amountPerOutput;
|
||||
|
||||
for( PartP2PFEPower target : PartP2PFEPower.this.getOutputs() )
|
||||
if (outputs.isEmpty())
|
||||
{
|
||||
for ( PartP2PFEPower o : PartP2PFEPower.this.getOutputs())
|
||||
outputs.add( o );
|
||||
}
|
||||
|
||||
while ( !outputs.isEmpty() ) {
|
||||
PartP2PFEPower target = outputs.poll();
|
||||
final IEnergyStorage output = target.getAttachedEnergyStorage();
|
||||
final int toSend = amountPerOutput + overflow;
|
||||
final int received = output.receiveEnergy( toSend, simulate );
|
||||
|
||||
@@ -425,6 +425,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
if( extracted != null )
|
||||
{
|
||||
possible = extracted.getStackSize();
|
||||
extracted.setCraftable( false );
|
||||
final IAEStack failed = Platform.poweredInsert( energy, destination, extracted, this.mySrc );
|
||||
|
||||
if( failed != null )
|
||||
|
||||
@@ -47,7 +47,7 @@ public abstract class InventoryAdaptor implements Iterable<ItemSlot>
|
||||
{
|
||||
if( te != null )
|
||||
{
|
||||
if( te.hasCapability( ITEM_REPOSITORY_CAPABILITY, d ) )
|
||||
if( ITEM_REPOSITORY_CAPABILITY != null && te.hasCapability( ITEM_REPOSITORY_CAPABILITY, d ) )
|
||||
{
|
||||
IItemRepository itemRepository = te.getCapability( ITEM_REPOSITORY_CAPABILITY, d );
|
||||
if (itemRepository != null){
|
||||
|
||||
@@ -56,6 +56,6 @@ public class ReadOnlyCollection<T> implements IReadOnlyCollection<T>
|
||||
@Override
|
||||
public boolean contains( final Object node )
|
||||
{
|
||||
return this.c.contains( node );
|
||||
return this.c.contains( (T) node );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,3 +206,4 @@ public class AdaptorItemRepository extends InventoryAdaptor
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.NoSuchElementException;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
|
||||
class ItemHandlerIterator implements Iterator<ItemSlot>
|
||||
public class ItemHandlerIterator implements Iterator<ItemSlot>
|
||||
{
|
||||
|
||||
private final IItemHandler itemHandler;
|
||||
@@ -34,7 +34,7 @@ class ItemHandlerIterator implements Iterator<ItemSlot>
|
||||
|
||||
private int slot = 0;
|
||||
|
||||
ItemHandlerIterator( IItemHandler itemHandler )
|
||||
public ItemHandlerIterator( IItemHandler itemHandler )
|
||||
{
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
* Copyright (c) 2013 - 2020, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
@@ -27,347 +26,291 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.core.Api;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack {
|
||||
private static final String NBT_STACKSIZE = "Cnt";
|
||||
private static final String NBT_REQUESTABLE = "Req";
|
||||
private static final String NBT_CRAFTABLE = "Craft";
|
||||
|
||||
public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack
|
||||
{
|
||||
private AESharedItemStack sharedStack;
|
||||
private Optional<OreReference> oreReference;
|
||||
private final AESharedItemStack sharedStack;
|
||||
private Optional<OreReference> oreReference;
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private String displayName;
|
||||
@SideOnly( Side.CLIENT )
|
||||
private List<String> tooltip;
|
||||
@SideOnly( Side.CLIENT )
|
||||
private ResourceLocation uniqueID;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private String displayName;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private List<String> tooltip;
|
||||
|
||||
private AEItemStack( final AEItemStack is )
|
||||
{
|
||||
this.setStackSize( is.getStackSize() );
|
||||
this.setCraftable( is.isCraftable() );
|
||||
this.setCountRequestable( is.getCountRequestable() );
|
||||
this.sharedStack = is.sharedStack;
|
||||
this.oreReference = is.oreReference;
|
||||
}
|
||||
private AEItemStack(final AEItemStack is) {
|
||||
this.setStackSize(is.getStackSize());
|
||||
this.setCraftable(is.isCraftable());
|
||||
this.setCountRequestable(is.getCountRequestable());
|
||||
this.sharedStack = is.sharedStack;
|
||||
this.oreReference = is.oreReference;
|
||||
}
|
||||
|
||||
private AEItemStack( final AESharedItemStack is, long size )
|
||||
{
|
||||
this.sharedStack = is;
|
||||
this.setStackSize( size );
|
||||
this.setCraftable( false );
|
||||
this.setCountRequestable( 0 );
|
||||
this.oreReference = OreHelper.INSTANCE.getOre( is.getDefinition() );
|
||||
}
|
||||
private AEItemStack(final AESharedItemStack is, long size) {
|
||||
this.sharedStack = is;
|
||||
this.setStackSize(size);
|
||||
this.setCraftable(false);
|
||||
this.setCountRequestable(0);
|
||||
this.oreReference = OreHelper.INSTANCE.getOre( is.getDefinition() );
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static AEItemStack fromItemStack( @Nonnull final ItemStack stack )
|
||||
{
|
||||
if( stack.isEmpty() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Nullable
|
||||
public static AEItemStack fromItemStack(@Nonnull final ItemStack stack) {
|
||||
if (stack.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new AEItemStack( AEItemStackRegistry.getRegisteredStack( stack ), stack.getCount() );
|
||||
}
|
||||
return new AEItemStack(AEItemStackRegistry.getRegisteredStack(stack), stack.getCount());
|
||||
}
|
||||
|
||||
public static IAEItemStack fromNBT( final NBTTagCompound i )
|
||||
{
|
||||
if( i == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public static IAEItemStack fromNBT(final NBTTagCompound i) {
|
||||
if (i == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final ItemStack itemstack = new ItemStack( i );
|
||||
if( itemstack.isEmpty() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
final ItemStack itemstack = new ItemStack(i);
|
||||
final AEItemStack item = AEItemStack.fromItemStack(itemstack);
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final AEItemStack item = AEItemStack.fromItemStack( itemstack );
|
||||
item.setStackSize( i.getLong( "Cnt" ) );
|
||||
item.setCountRequestable( i.getLong( "Req" ) );
|
||||
item.setCraftable( i.getBoolean( "Craft" ) );
|
||||
return item;
|
||||
}
|
||||
item.setStackSize(i.getLong(NBT_STACKSIZE));
|
||||
item.setCountRequestable(i.getLong(NBT_REQUESTABLE));
|
||||
item.setCraftable(i.getBoolean(NBT_CRAFTABLE));
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound i )
|
||||
{
|
||||
this.getDefinition().writeToNBT( i );
|
||||
i.setLong( "Cnt", this.getStackSize() );
|
||||
i.setLong( "Req", this.getCountRequestable() );
|
||||
i.setBoolean( "Craft", this.isCraftable() );
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound i) {
|
||||
final NBTTagCompound itemStack = new NBTTagCompound();
|
||||
this.getDefinition().writeToNBT(itemStack);
|
||||
|
||||
public static AEItemStack fromPacket( final ByteBuf data )
|
||||
{
|
||||
final byte mask = data.readByte();
|
||||
final byte stackType = (byte) ( ( mask & 0x0C ) >> 2 );
|
||||
final byte countReqType = (byte) ( ( mask & 0x30 ) >> 4 );
|
||||
final boolean isCraftable = ( mask & 0x40 ) > 0;
|
||||
i.setLong(NBT_STACKSIZE, this.getStackSize());
|
||||
i.setLong(NBT_REQUESTABLE, this.getCountRequestable());
|
||||
i.setBoolean(NBT_CRAFTABLE, this.isCraftable());
|
||||
}
|
||||
|
||||
final ItemStack itemstack = new ItemStack( ByteBufUtils.readTag( data ) );
|
||||
final long stackSize = getPacketValue( stackType, data );
|
||||
final long countRequestable = getPacketValue( countReqType, data );
|
||||
public static AEItemStack fromPacket( final ByteBuf data )
|
||||
{
|
||||
final byte mask = data.readByte();
|
||||
final byte stackType = (byte) ( ( mask & 0x0C ) >> 2 );
|
||||
final byte countReqType = (byte) ( ( mask & 0x30 ) >> 4 );
|
||||
final boolean isCraftable = ( mask & 0x40 ) > 0;
|
||||
|
||||
if( itemstack.isEmpty() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
final ItemStack itemstack = new ItemStack( ByteBufUtils.readTag( data ) );
|
||||
final long stackSize = getPacketValue( stackType, data );
|
||||
final long countRequestable = getPacketValue( countReqType, data );
|
||||
|
||||
final AEItemStack item = new AEItemStack( AEItemStackRegistry.getRegisteredStack( itemstack ), stackSize );
|
||||
item.setCountRequestable( countRequestable );
|
||||
item.setCraftable( isCraftable );
|
||||
return item;
|
||||
}
|
||||
if( itemstack.isEmpty() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToPacket( final ByteBuf i )
|
||||
{
|
||||
final byte mask = (byte) ( ( this.getType( this.getStackSize() ) << 2 ) | ( this
|
||||
.getType( this.getCountRequestable() ) << 4 ) | ( (byte) ( this.isCraftable() ? 1 : 0 ) << 6 ) | ( this.hasTagCompound() ? 1 : 0 ) << 7 );
|
||||
final AEItemStack item = new AEItemStack( AEItemStackRegistry.getRegisteredStack( itemstack ), stackSize );
|
||||
item.setCountRequestable( countRequestable );
|
||||
item.setCraftable( isCraftable );
|
||||
return item;
|
||||
}
|
||||
|
||||
i.writeByte( mask );
|
||||
ByteBufUtils.writeTag( i, this.getDefinition().serializeNBT() );
|
||||
this.putPacketValue( i, this.getStackSize() );
|
||||
this.putPacketValue( i, this.getCountRequestable() );
|
||||
}
|
||||
@Override
|
||||
public void writeToPacket( final ByteBuf i )
|
||||
{
|
||||
final byte mask = (byte) ( ( this.getType( this.getStackSize() ) << 2 ) | ( this
|
||||
.getType( this.getCountRequestable() ) << 4 ) | ( (byte) ( this.isCraftable() ? 1 : 0 ) << 6 ) | ( this.hasTagCompound() ? 1 : 0 ) << 7 );
|
||||
|
||||
@Override
|
||||
public void add( final IAEItemStack option )
|
||||
{
|
||||
if( option == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
i.writeByte( mask );
|
||||
ByteBufUtils.writeTag( i, this.getDefinition().serializeNBT() );
|
||||
this.putPacketValue( i, this.getStackSize() );
|
||||
this.putPacketValue( i, this.getCountRequestable() );
|
||||
}
|
||||
|
||||
this.incStackSize( option.getStackSize() );
|
||||
this.setCountRequestable( this.getCountRequestable() + option.getCountRequestable() );
|
||||
this.setCraftable( this.isCraftable() || option.isCraftable() );
|
||||
}
|
||||
@Override
|
||||
public void add(final IAEItemStack option) {
|
||||
if (option == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fuzzyComparison( final IAEItemStack other, final FuzzyMode mode )
|
||||
{
|
||||
if( mode == FuzzyMode.IGNORE_ALL && OreHelper.INSTANCE.sameOre( this, other ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
this.incStackSize(option.getStackSize());
|
||||
this.setCountRequestable(this.getCountRequestable() + option.getCountRequestable());
|
||||
this.setCraftable(this.isCraftable() || option.isCraftable());
|
||||
}
|
||||
|
||||
final ItemStack itemStack = this.getDefinition();
|
||||
final ItemStack otherStack = other.getDefinition();
|
||||
@Override
|
||||
public boolean fuzzyComparison(final IAEItemStack other, final FuzzyMode mode) {
|
||||
final ItemStack itemStack = this.getDefinition();
|
||||
final ItemStack otherStack = other.getDefinition();
|
||||
|
||||
return this.fuzzyItemStackComparison( itemStack, otherStack, mode );
|
||||
}
|
||||
return this.fuzzyItemStackComparison(itemStack, otherStack, mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack copy()
|
||||
{
|
||||
return new AEItemStack( this );
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack copy() {
|
||||
return new AEItemStack(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItem()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isItem()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFluid()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isFluid()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
|
||||
}
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel() {
|
||||
return Api.INSTANCE.storage().getStorageChannel(IItemStorageChannel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack createItemStack()
|
||||
{
|
||||
return ItemHandlerHelper.copyStackWithSize( this.getDefinition(), (int) Math.min( Integer.MAX_VALUE, this.getStackSize() ) );
|
||||
}
|
||||
@Override
|
||||
public ItemStack createItemStack() {
|
||||
return ItemHandlerHelper.copyStackWithSize(this.getDefinition(),
|
||||
(int) Math.min(Integer.MAX_VALUE, this.getStackSize()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getItem()
|
||||
{
|
||||
return this.getDefinition().getItem();
|
||||
}
|
||||
@Override
|
||||
public Item getItem() {
|
||||
return this.getDefinition().getItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemDamage()
|
||||
{
|
||||
return this.sharedStack.getItemDamage();
|
||||
}
|
||||
@Override
|
||||
public int getItemDamage() {
|
||||
return this.sharedStack.getItemDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sameOre( final IAEItemStack is )
|
||||
{
|
||||
return OreHelper.INSTANCE.sameOre( this, is );
|
||||
}
|
||||
@Override
|
||||
public boolean sameOre( final IAEItemStack is )
|
||||
{
|
||||
return OreHelper.INSTANCE.sameOre( this, is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameType( final IAEItemStack otherStack )
|
||||
{
|
||||
if( otherStack == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isSameType(final IAEItemStack otherStack) {
|
||||
if (otherStack == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Objects.equals( this.sharedStack, ( (AEItemStack) otherStack ).sharedStack );
|
||||
}
|
||||
return Objects.equals(this.sharedStack, ((AEItemStack) otherStack).sharedStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameType( final ItemStack otherStack )
|
||||
{
|
||||
if( otherStack.isEmpty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int oldSize = otherStack.getCount();
|
||||
@Override
|
||||
public boolean isSameType(final ItemStack otherStack) {
|
||||
if (otherStack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
int oldSize = otherStack.getCount();
|
||||
|
||||
otherStack.setCount( 1 );
|
||||
boolean ret = ItemStack.areItemStacksEqual( this.getDefinition(), otherStack );
|
||||
otherStack.setCount( oldSize );
|
||||
otherStack.setCount(1);
|
||||
boolean ret = ItemStack.areItemStacksEqual(this.getDefinition(), otherStack);
|
||||
otherStack.setCount(oldSize);
|
||||
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return this.sharedStack.hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.sharedStack.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( final Object ia )
|
||||
{
|
||||
if( ia instanceof AEItemStack )
|
||||
{
|
||||
return this.isSameType( (AEItemStack) ia );
|
||||
}
|
||||
else if( ia instanceof ItemStack )
|
||||
{
|
||||
return this.isSameType( (ItemStack) ia );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final Object ia) {
|
||||
if (ia instanceof AEItemStack) {
|
||||
return this.isSameType((AEItemStack) ia);
|
||||
} else if (ia instanceof ItemStack) {
|
||||
// this actually breaks the equals contract (being equals to unrelated classes)
|
||||
return equals((ItemStack) ia);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.getStackSize() + "x" + this.getDefinition().getItem().getUnlocalizedName() + "@" + this.getDefinition().getItemDamage();
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final ItemStack is) {
|
||||
return this.isSameType(is);
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
public List<String> getToolTip()
|
||||
{
|
||||
if( this.tooltip == null )
|
||||
{
|
||||
this.tooltip = Platform.getTooltip( this.asItemStackRepresentation() );
|
||||
}
|
||||
return this.tooltip;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getStackSize() + "x" + this.getDefinition().getItem().getRegistryName();
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
public String getDisplayName()
|
||||
{
|
||||
if( this.displayName == null )
|
||||
{
|
||||
this.displayName = Platform.getItemDisplayName( this.asItemStackRepresentation() );
|
||||
}
|
||||
return this.displayName;
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
public List<String> getToolTip() {
|
||||
if (this.tooltip == null) {
|
||||
this.tooltip = Platform.getTooltip(this.asItemStackRepresentation());
|
||||
}
|
||||
return this.tooltip;
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
public String getModID()
|
||||
{
|
||||
if( this.uniqueID == null )
|
||||
{
|
||||
this.uniqueID = Item.REGISTRY.getNameForObject( this.getDefinition().getItem() );
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getDisplayName() {
|
||||
if (this.displayName == null) {
|
||||
this.displayName = Platform.getItemDisplayName(this.asItemStackRepresentation());
|
||||
}
|
||||
return this.displayName;
|
||||
}
|
||||
|
||||
if( this.uniqueID == null )
|
||||
{
|
||||
return "** Null";
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getModID() {
|
||||
return this.getDefinition().getItem().getRegistryName().getResourceDomain();
|
||||
}
|
||||
|
||||
return this.uniqueID.getResourceDomain() == null ? "** Null" : this.uniqueID.getResourceDomain();
|
||||
}
|
||||
public Optional<OreReference> getOre()
|
||||
{
|
||||
return this.oreReference;
|
||||
}
|
||||
|
||||
public Optional<OreReference> getOre()
|
||||
{
|
||||
return this.oreReference;
|
||||
}
|
||||
@Override
|
||||
public boolean hasTagCompound() {
|
||||
return this.getDefinition().hasTagCompound();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTagCompound()
|
||||
{
|
||||
return this.getDefinition().hasTagCompound();
|
||||
}
|
||||
@Override
|
||||
public ItemStack asItemStackRepresentation() {
|
||||
return this.getDefinition().copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack asItemStackRepresentation()
|
||||
{
|
||||
return this.getDefinition().copy();
|
||||
}
|
||||
@Override
|
||||
public ItemStack getDefinition() {
|
||||
return this.sharedStack.getDefinition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getDefinition()
|
||||
{
|
||||
return this.sharedStack.getDefinition();
|
||||
}
|
||||
AESharedItemStack getSharedStack() {
|
||||
return this.sharedStack;
|
||||
}
|
||||
|
||||
AESharedItemStack getSharedStack()
|
||||
{
|
||||
return this.sharedStack;
|
||||
}
|
||||
private boolean fuzzyItemStackComparison(ItemStack a, ItemStack b, FuzzyMode mode) {
|
||||
if (a.getItem() == b.getItem() && a.getItem().isDamageable()) {
|
||||
if (mode == FuzzyMode.IGNORE_ALL) {
|
||||
return true;
|
||||
} else if (mode == FuzzyMode.PERCENT_99) {
|
||||
return a.getItemDamage() > 1 == b.getItemDamage() > 1;
|
||||
} else {
|
||||
final float percentDamageOfA = (float) a.getItemDamage() / a.getMaxDamage();
|
||||
final float percentDamageOfB = (float) b.getItemDamage() / b.getMaxDamage();
|
||||
|
||||
private boolean fuzzyItemStackComparison( ItemStack a, ItemStack b, FuzzyMode mode )
|
||||
{
|
||||
if( a.getItem() == b.getItem() )
|
||||
{
|
||||
if( a.getItem().isDamageable() )
|
||||
{
|
||||
if( mode == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if( mode == FuzzyMode.PERCENT_99 )
|
||||
{
|
||||
return ( a.getItemDamage() > 1 ) == ( b.getItemDamage() > 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
final float percentDamageOfA = (float) a.getItemDamage() / (float) a.getMaxDamage();
|
||||
final float percentDamageOfB = (float) b.getItemDamage() / (float) b.getMaxDamage();
|
||||
|
||||
return ( percentDamageOfA > mode.breakPoint ) == ( percentDamageOfB > mode.breakPoint );
|
||||
}
|
||||
}
|
||||
|
||||
return a.getMetadata() == b.getMetadata();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return percentDamageOfA > mode.breakPoint == percentDamageOfB > mode.breakPoint;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
@@ -31,56 +30,34 @@ import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.util.Platform;
|
||||
public final class AEItemStackRegistry {
|
||||
private static final WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> REGISTRY = new WeakHashMap<>();
|
||||
|
||||
private AEItemStackRegistry() {
|
||||
}
|
||||
|
||||
public final class AEItemStackRegistry
|
||||
{
|
||||
private static final WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> SERVER_REGISTRY = new WeakHashMap<>();
|
||||
private static final WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> CLIENT_REGISTRY = new WeakHashMap<>();
|
||||
static synchronized AESharedItemStack getRegisteredStack(final @Nonnull ItemStack itemStack) {
|
||||
if (itemStack.isEmpty()) {
|
||||
throw new IllegalArgumentException("stack cannot be empty");
|
||||
}
|
||||
|
||||
private AEItemStackRegistry()
|
||||
{
|
||||
}
|
||||
int oldStackSize = itemStack.getCount();
|
||||
itemStack.setCount(1);
|
||||
|
||||
private static WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> registry()
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return CLIENT_REGISTRY;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SERVER_REGISTRY;
|
||||
}
|
||||
}
|
||||
AESharedItemStack search = new AESharedItemStack(itemStack);
|
||||
WeakReference<AESharedItemStack> weak = REGISTRY.get(search);
|
||||
AESharedItemStack ret = null;
|
||||
|
||||
static synchronized AESharedItemStack getRegisteredStack( final @Nonnull ItemStack itemStack )
|
||||
{
|
||||
if( itemStack.isEmpty() )
|
||||
{
|
||||
throw new IllegalArgumentException( "stack cannot be empty" );
|
||||
}
|
||||
if (weak != null) {
|
||||
ret = weak.get();
|
||||
}
|
||||
|
||||
int oldStackSize = itemStack.getCount();
|
||||
itemStack.setCount( 1 );
|
||||
if (ret == null) {
|
||||
ret = new AESharedItemStack(itemStack.copy());
|
||||
REGISTRY.put(ret, new WeakReference<>(ret));
|
||||
}
|
||||
itemStack.setCount(oldStackSize);
|
||||
|
||||
AESharedItemStack search = new AESharedItemStack( itemStack );
|
||||
WeakReference<AESharedItemStack> weak = registry().get( search );
|
||||
AESharedItemStack ret = null;
|
||||
|
||||
if( weak != null )
|
||||
{
|
||||
ret = weak.get();
|
||||
}
|
||||
|
||||
if( ret == null )
|
||||
{
|
||||
ret = new AESharedItemStack( itemStack.copy() );
|
||||
registry().put( ret, new WeakReference<>( ret ) );
|
||||
}
|
||||
itemStack.setCount( oldStackSize );
|
||||
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,263 +18,76 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
final class AESharedItemStack {
|
||||
|
||||
private final ItemStack itemStack;
|
||||
private final int itemId;
|
||||
private final int itemDamage;
|
||||
private final int hashCode;
|
||||
|
||||
final class AESharedItemStack implements Comparable<AESharedItemStack>
|
||||
{
|
||||
private static final NBTTagCompound LOW_TAG = new NBTTagCompound();
|
||||
private static final NBTTagCompound HIGH_TAG = new NBTTagCompound();
|
||||
public AESharedItemStack(final ItemStack itemStack) {
|
||||
this(itemStack, itemStack.getItemDamage());
|
||||
}
|
||||
|
||||
private final ItemStack itemStack;
|
||||
private final int itemId;
|
||||
private final int itemDamage;
|
||||
private final int hashCode;
|
||||
/**
|
||||
* A constructor to explicitly set the damage value and not fetch it from the {@link ItemStack}
|
||||
*
|
||||
* @param itemStack The {@link ItemStack} to filter
|
||||
* @param damage The damage of the item
|
||||
*/
|
||||
private AESharedItemStack(ItemStack itemStack, int damage) {
|
||||
this.itemStack = itemStack;
|
||||
this.itemId = Item.getIdFromItem(itemStack.getItem());
|
||||
this.itemDamage = damage;
|
||||
|
||||
public AESharedItemStack( final ItemStack itemStack )
|
||||
{
|
||||
this.itemStack = itemStack;
|
||||
this.itemId = Item.getIdFromItem( itemStack.getItem() );
|
||||
this.itemDamage = itemStack.getItemDamage();
|
||||
this.hashCode = this.makeHashCode();
|
||||
}
|
||||
// Ensure this is always called last.
|
||||
this.hashCode = this.makeHashCode();
|
||||
}
|
||||
|
||||
Bounds getBounds( final FuzzyMode fuzzy, final boolean ignoreMeta )
|
||||
{
|
||||
return new Bounds( this.itemStack, fuzzy, ignoreMeta );
|
||||
}
|
||||
ItemStack getDefinition() {
|
||||
return this.itemStack;
|
||||
}
|
||||
|
||||
ItemStack getDefinition()
|
||||
{
|
||||
return this.itemStack;
|
||||
}
|
||||
int getItemDamage() {
|
||||
return this.itemDamage;
|
||||
}
|
||||
|
||||
int getItemDamage()
|
||||
{
|
||||
return this.itemDamage;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.hashCode;
|
||||
}
|
||||
|
||||
int getItemID()
|
||||
{
|
||||
return this.itemId;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof AESharedItemStack)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return this.hashCode;
|
||||
}
|
||||
final AESharedItemStack other = (AESharedItemStack) obj;
|
||||
Preconditions.checkState(this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1");
|
||||
Preconditions.checkArgument(other.getDefinition().getCount() == 1, "ItemStack#getCount() has to be 1");
|
||||
|
||||
@Override
|
||||
public boolean equals( final Object obj )
|
||||
{
|
||||
if( obj instanceof AESharedItemStack )
|
||||
{
|
||||
final AESharedItemStack other = (AESharedItemStack) obj;
|
||||
if (this.itemStack == other.itemStack) {
|
||||
return true;
|
||||
}
|
||||
return ItemStack.areItemStacksEqual(this.itemStack, other.itemStack);
|
||||
}
|
||||
|
||||
Preconditions.checkState( this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1" );
|
||||
Preconditions.checkArgument( other.getDefinition().getCount() == 1, "ItemStack#getCount() has to be 1" );
|
||||
private int makeHashCode() {
|
||||
return Objects.hash(
|
||||
this.itemId,
|
||||
this.itemDamage,
|
||||
this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound() : 0);
|
||||
}
|
||||
|
||||
if( this.itemStack == other.itemStack )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return ItemStack.areItemStacksEqual( this.itemStack, other.itemStack );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo( final AESharedItemStack b )
|
||||
{
|
||||
Preconditions.checkState( this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1" );
|
||||
Preconditions.checkArgument( b.getDefinition().getCount() == 1, "ItemStack#getCount() has to be 1" );
|
||||
|
||||
if( this.itemStack == b.getDefinition() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
final int id = this.itemId - b.itemId;
|
||||
if( id != 0 )
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
final int damageValue = this.itemDamage - b.itemDamage;
|
||||
if( damageValue != 0 )
|
||||
{
|
||||
return damageValue;
|
||||
}
|
||||
|
||||
final int nbt = this.compareNBT( b.getDefinition() );
|
||||
if( nbt != 0 )
|
||||
{
|
||||
return nbt;
|
||||
}
|
||||
|
||||
if( !this.itemStack.areCapsCompatible( b.getDefinition() ) )
|
||||
{
|
||||
return System.identityHashCode( this.itemStack ) - System.identityHashCode( b.getDefinition() );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int compareNBT( final ItemStack b )
|
||||
{
|
||||
if( this.itemStack.getTagCompound() == b.getTagCompound() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if( this.itemStack.getTagCompound() == LOW_TAG || b.getTagCompound() == HIGH_TAG )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if( this.itemStack.getTagCompound() == HIGH_TAG || b.getTagCompound() == LOW_TAG )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return System.identityHashCode( this.itemStack.getTagCompound() ) - System.identityHashCode( b.getTagCompound() );
|
||||
}
|
||||
|
||||
private int makeHashCode()
|
||||
{
|
||||
return Objects.hash( this.itemId, this.itemDamage, this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound() : 0 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the lower and upper bounds for a specific shared itemstack.
|
||||
*/
|
||||
public static final class Bounds
|
||||
{
|
||||
/**
|
||||
* Bounds enforced by {@link ItemStack#isEmpty()}
|
||||
*/
|
||||
private static final int MIN_DAMAGE_VALUE = 0;
|
||||
private static final int MAX_DAMAGE_VALUE = 65535;
|
||||
|
||||
private final AESharedItemStack lower;
|
||||
private final AESharedItemStack upper;
|
||||
|
||||
public Bounds( final ItemStack stack, final FuzzyMode fuzzy, final boolean ignoreMeta )
|
||||
{
|
||||
Preconditions.checkState( !stack.isEmpty(), "ItemStack#isEmpty() has to be false" );
|
||||
Preconditions.checkState( stack.getCount() == 1, "ItemStack#getCount() has to be 1" );
|
||||
|
||||
final NBTTagCompound tag = stack.hasTagCompound() ? stack.getTagCompound() : null;
|
||||
|
||||
this.lower = this.makeLowerBound( stack, tag, fuzzy, ignoreMeta );
|
||||
this.upper = this.makeUpperBound( stack, tag, fuzzy, ignoreMeta );
|
||||
}
|
||||
|
||||
public AESharedItemStack lower()
|
||||
{
|
||||
return this.lower;
|
||||
}
|
||||
|
||||
public AESharedItemStack upper()
|
||||
{
|
||||
return this.upper;
|
||||
}
|
||||
|
||||
private AESharedItemStack makeLowerBound( final ItemStack itemStack, final NBTTagCompound tag, final FuzzyMode fuzzy, final boolean ignoreMeta )
|
||||
{
|
||||
final ItemStack newDef = itemStack.copy();
|
||||
|
||||
if( ignoreMeta )
|
||||
{
|
||||
newDef.setItemDamage( MIN_DAMAGE_VALUE );
|
||||
newDef.setTagCompound( tag );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( newDef.getItem().isDamageable() )
|
||||
{
|
||||
if (itemStack.getMaxDamage() == 0)
|
||||
{
|
||||
newDef.setItemDamage(itemStack.getItemDamage() );
|
||||
}
|
||||
else if ( fuzzy == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
newDef.setItemDamage( MIN_DAMAGE_VALUE );
|
||||
}
|
||||
else if( fuzzy == FuzzyMode.PERCENT_99 )
|
||||
{
|
||||
if( itemStack.getItemDamage() == MIN_DAMAGE_VALUE )
|
||||
{
|
||||
newDef.setItemDamage( MIN_DAMAGE_VALUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
newDef.setItemDamage( MIN_DAMAGE_VALUE + 1 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final int breakpoint = fuzzy.calculateBreakPoint( itemStack.getMaxDamage() );
|
||||
final int damage = breakpoint <= itemStack.getItemDamage() ? breakpoint : 0;
|
||||
newDef.setItemDamage( damage );
|
||||
}
|
||||
}
|
||||
newDef.setTagCompound( LOW_TAG );
|
||||
}
|
||||
|
||||
return new AESharedItemStack( newDef );
|
||||
}
|
||||
|
||||
private AESharedItemStack makeUpperBound( final ItemStack itemStack, final NBTTagCompound tag, final FuzzyMode fuzzy, final boolean ignoreMeta )
|
||||
{
|
||||
final ItemStack newDef = itemStack.copy();
|
||||
|
||||
if( ignoreMeta )
|
||||
{
|
||||
newDef.setItemDamage( MAX_DAMAGE_VALUE );
|
||||
newDef.setTagCompound( tag );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( newDef.getItem().isDamageable() )
|
||||
{
|
||||
if (itemStack.getMaxDamage() == 0)
|
||||
{
|
||||
newDef.setItemDamage(itemStack.getItemDamage() );
|
||||
}
|
||||
else if ( fuzzy == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
newDef.setItemDamage( itemStack.getMaxDamage() + 1 );
|
||||
}
|
||||
else if( fuzzy == FuzzyMode.PERCENT_99 )
|
||||
{
|
||||
if( itemStack.getItemDamage() == MIN_DAMAGE_VALUE )
|
||||
{
|
||||
newDef.setItemDamage( MIN_DAMAGE_VALUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
newDef.setItemDamage( itemStack.getMaxDamage() + 1 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final int breakpoint = fuzzy.calculateBreakPoint( itemStack.getMaxDamage() );
|
||||
final int damage = itemStack.getItemDamage() < breakpoint ? breakpoint - 1 : itemStack.getMaxDamage() + 1;
|
||||
newDef.setItemDamage( damage );
|
||||
}
|
||||
}
|
||||
newDef.setTagCompound( HIGH_TAG );
|
||||
}
|
||||
|
||||
return new AESharedItemStack( newDef );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,169 +18,152 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
public abstract class AEStack<T extends IAEStack<T>> implements IAEStack<T> {
|
||||
|
||||
public abstract class AEStack<StackType extends IAEStack<StackType>> implements IAEStack<StackType>
|
||||
{
|
||||
private boolean isCraftable;
|
||||
private long stackSize;
|
||||
private long countRequestable;
|
||||
|
||||
private boolean isCraftable;
|
||||
private long stackSize;
|
||||
private long countRequestable;
|
||||
protected static long getPacketValue( final byte type, final ByteBuf tag )
|
||||
{
|
||||
if( type == 0 )
|
||||
{
|
||||
long l = tag.readByte();
|
||||
l -= Byte.MIN_VALUE;
|
||||
return l;
|
||||
}
|
||||
else if( type == 1 )
|
||||
{
|
||||
long l = tag.readShort();
|
||||
l -= Short.MIN_VALUE;
|
||||
return l;
|
||||
}
|
||||
else if( type == 2 )
|
||||
{
|
||||
long l = tag.readInt();
|
||||
l -= Integer.MIN_VALUE;
|
||||
return l;
|
||||
}
|
||||
|
||||
protected static long getPacketValue( final byte type, final ByteBuf tag )
|
||||
{
|
||||
if( type == 0 )
|
||||
{
|
||||
long l = tag.readByte();
|
||||
l -= Byte.MIN_VALUE;
|
||||
return l;
|
||||
}
|
||||
else if( type == 1 )
|
||||
{
|
||||
long l = tag.readShort();
|
||||
l -= Short.MIN_VALUE;
|
||||
return l;
|
||||
}
|
||||
else if( type == 2 )
|
||||
{
|
||||
long l = tag.readInt();
|
||||
l -= Integer.MIN_VALUE;
|
||||
return l;
|
||||
}
|
||||
return tag.readLong();
|
||||
}
|
||||
|
||||
return tag.readLong();
|
||||
}
|
||||
@Override
|
||||
public long getStackSize() {
|
||||
return this.stackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStackSize()
|
||||
{
|
||||
return this.stackSize;
|
||||
}
|
||||
@Override
|
||||
public T setStackSize(final long ss) {
|
||||
this.stackSize = ss;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackType setStackSize( final long ss )
|
||||
{
|
||||
this.stackSize = ss;
|
||||
return (StackType) this;
|
||||
}
|
||||
@Override
|
||||
public long getCountRequestable() {
|
||||
return this.countRequestable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCountRequestable()
|
||||
{
|
||||
return this.countRequestable;
|
||||
}
|
||||
@Override
|
||||
public T setCountRequestable(final long countRequestable) {
|
||||
this.countRequestable = countRequestable;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackType setCountRequestable( final long countRequestable )
|
||||
{
|
||||
this.countRequestable = countRequestable;
|
||||
return (StackType) this;
|
||||
}
|
||||
@Override
|
||||
public boolean isCraftable() {
|
||||
return this.isCraftable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCraftable()
|
||||
{
|
||||
return this.isCraftable;
|
||||
}
|
||||
@Override
|
||||
public T setCraftable(final boolean isCraftable) {
|
||||
this.isCraftable = isCraftable;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackType setCraftable( final boolean isCraftable )
|
||||
{
|
||||
this.isCraftable = isCraftable;
|
||||
return (StackType) this;
|
||||
}
|
||||
@Override
|
||||
public T reset() {
|
||||
this.stackSize = 0;
|
||||
this.setCountRequestable(0);
|
||||
this.setCraftable(false);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackType reset()
|
||||
{
|
||||
this.stackSize = 0;
|
||||
// priority = Integer.MIN_VALUE;
|
||||
this.setCountRequestable( 0 );
|
||||
this.setCraftable( false );
|
||||
return (StackType) this;
|
||||
}
|
||||
@Override
|
||||
public T empty() {
|
||||
final T dup = this.copy();
|
||||
dup.reset();
|
||||
return dup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackType empty()
|
||||
{
|
||||
final StackType dup = this.copy();
|
||||
dup.reset();
|
||||
return dup;
|
||||
}
|
||||
@Override
|
||||
public boolean isMeaningful() {
|
||||
return this.stackSize != 0 || this.countRequestable > 0 || this.isCraftable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMeaningful()
|
||||
{
|
||||
return this.stackSize != 0 || this.countRequestable > 0 || this.isCraftable;
|
||||
}
|
||||
@Override
|
||||
public void incStackSize(final long i) {
|
||||
this.stackSize += i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incStackSize( final long i )
|
||||
{
|
||||
this.stackSize += i;
|
||||
}
|
||||
@Override
|
||||
public void decStackSize(final long i) {
|
||||
this.stackSize -= i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decStackSize( final long i )
|
||||
{
|
||||
this.stackSize -= i;
|
||||
}
|
||||
@Override
|
||||
public void incCountRequestable(final long i) {
|
||||
this.countRequestable += i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incCountRequestable( final long i )
|
||||
{
|
||||
this.countRequestable += i;
|
||||
}
|
||||
@Override
|
||||
public void decCountRequestable(final long i) {
|
||||
this.countRequestable -= i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decCountRequestable( final long i )
|
||||
{
|
||||
this.countRequestable -= i;
|
||||
}
|
||||
protected byte getType( final long num )
|
||||
{
|
||||
if( num <= 255 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if( num <= 65535 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if( num <= 4294967295L )
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
protected byte getType( final long num )
|
||||
{
|
||||
if( num <= 255 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if( num <= 65535 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else if( num <= 4294967295L )
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
protected abstract boolean hasTagCompound();
|
||||
|
||||
protected abstract boolean hasTagCompound();
|
||||
|
||||
protected void putPacketValue( final ByteBuf tag, final long num )
|
||||
{
|
||||
if( num <= 255 )
|
||||
{
|
||||
tag.writeByte( (byte) ( num + Byte.MIN_VALUE ) );
|
||||
}
|
||||
else if( num <= 65535 )
|
||||
{
|
||||
tag.writeShort( (short) ( num + Short.MIN_VALUE ) );
|
||||
}
|
||||
else if( num <= 4294967295L )
|
||||
{
|
||||
tag.writeInt( (int) ( num + Integer.MIN_VALUE ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
tag.writeLong( num );
|
||||
}
|
||||
}
|
||||
protected void putPacketValue( final ByteBuf tag, final long num )
|
||||
{
|
||||
if( num <= 255 )
|
||||
{
|
||||
tag.writeByte( (byte) ( num + Byte.MIN_VALUE ) );
|
||||
}
|
||||
else if( num <= 65535 )
|
||||
{
|
||||
tag.writeShort( (short) ( num + Short.MIN_VALUE ) );
|
||||
}
|
||||
else if( num <= 4294967295L )
|
||||
{
|
||||
tag.writeInt( (int) ( num + Integer.MIN_VALUE ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
tag.writeLong( num );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2021, TeamAppliedEnergistics, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectAVLTreeMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectSortedMap;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
/**
|
||||
* This variant list is optimized for damageable items, and supports selecting durability ranges with
|
||||
* {@link #findFuzzy(IAEItemStack, FuzzyMode)}.
|
||||
*/
|
||||
class FuzzyItemVariantList extends ItemVariantList {
|
||||
|
||||
static final SharedStackComparator COMPARATOR = new SharedStackComparator();
|
||||
|
||||
// NOTE: We only use Object as they key here so we can pass our special DamageBounds to the subMap method.
|
||||
// We NEVER put any keys in this map that are not AESharedItemStacks.
|
||||
private final Object2ObjectSortedMap<Object, IAEItemStack> records = new Object2ObjectAVLTreeMap<>(COMPARATOR);
|
||||
|
||||
@Override
|
||||
public Collection<IAEItemStack> findFuzzy(final IAEItemStack filter, final FuzzyMode fuzzy) {
|
||||
ItemStack itemStack = filter.getDefinition();
|
||||
|
||||
ItemDamageBound lowerBound = makeLowerBound(itemStack, fuzzy);
|
||||
ItemDamageBound upperBound = makeUpperBound(itemStack, fuzzy);
|
||||
Preconditions.checkState(lowerBound.itemDamage > upperBound.itemDamage);
|
||||
|
||||
return this.records.subMap(lowerBound, upperBound).values();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
Map<AESharedItemStack, IAEItemStack> getRecords() {
|
||||
// We ensure on our end that we NEVER use anything but AESharedItemStack as the key in this map
|
||||
return (Map<AESharedItemStack, IAEItemStack>) (Object) this.records;
|
||||
}
|
||||
|
||||
static class ItemDamageBound {
|
||||
final int itemDamage;
|
||||
|
||||
public ItemDamageBound(int itemDamage) {
|
||||
this.itemDamage = itemDamage;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This comparator creates a strict and total ordering over all {@link AESharedItemStack} of the same item. To
|
||||
* support selecting ranges of durability, it is defined for type {@link Object} and also accepts
|
||||
* {@link ItemDamageBound} as an argument to compare against.
|
||||
*/
|
||||
static class SharedStackComparator implements Comparator<Object> {
|
||||
@Override
|
||||
public int compare(Object a, Object b) {
|
||||
// Either argument can either be a damage bound or a shared item stack
|
||||
// Since we never put damage bounds into the map as keys, only one
|
||||
// of the two arguments can possibly be a bound
|
||||
ItemDamageBound boundA = null;
|
||||
AESharedItemStack stackA = null;
|
||||
int itemDamageA;
|
||||
if (a instanceof ItemDamageBound) {
|
||||
boundA = (ItemDamageBound) a;
|
||||
itemDamageA = boundA.itemDamage;
|
||||
} else {
|
||||
stackA = (AESharedItemStack) a;
|
||||
itemDamageA = stackA.getItemDamage();
|
||||
}
|
||||
ItemDamageBound boundB = null;
|
||||
AESharedItemStack stackB = null;
|
||||
int itemDamageB;
|
||||
if (b instanceof ItemDamageBound) {
|
||||
boundB = (ItemDamageBound) b;
|
||||
itemDamageB = boundB.itemDamage;
|
||||
} else {
|
||||
stackB = (AESharedItemStack) b;
|
||||
itemDamageB = stackB.getItemDamage();
|
||||
}
|
||||
|
||||
// When either argument is a damage bound, we just compare the damage values because it is used
|
||||
// only to get a certain damage range out of the map.
|
||||
if (boundA != null || boundB != null) {
|
||||
return Integer.compare(itemDamageB, itemDamageA);
|
||||
}
|
||||
|
||||
ItemStack itemStackA = stackA.getDefinition();
|
||||
ItemStack itemStackB = stackB.getDefinition();
|
||||
Preconditions.checkState(itemStackA.getCount() == 1, "ItemStack#getCount() has to be 1");
|
||||
Preconditions.checkArgument(itemStackB.getCount() == 1, "ItemStack#getCount() has to be 1");
|
||||
|
||||
if (itemStackA == itemStackB) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Damaged items are sorted before undamaged items
|
||||
final int damageValue = Integer.compare(itemDamageB, itemDamageA);
|
||||
if (damageValue != 0) {
|
||||
return damageValue;
|
||||
}
|
||||
|
||||
// As a final tie breaker, order by the object identity of the item stack
|
||||
// While this will order seemingly at random, we only need the order of
|
||||
// damage values to be predictable, while still having to satisfy the
|
||||
// complete order requirements of the sorted map
|
||||
return Long.compare(System.identityHashCode(itemStackA), System.identityHashCode(itemStackB));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Minecraft reverses the damage values. So anything with a damage of 0 is undamaged and increases the more damaged
|
||||
* the item is.
|
||||
* <p>
|
||||
* Further the used subMap follows [MAX_DAMAGE, MIN_DAMAGE), so to include undamaged items, we have to start with a
|
||||
* lower damage value than 0, while it is fine to use {@link ItemStack#getMaxDamage()} for the upper bound.
|
||||
*/
|
||||
private static final int MIN_DAMAGE_VALUE = -1;
|
||||
|
||||
/*
|
||||
* Keep in mind that the stack order is from most damaged to least damaged, so this lower bound will actually be a
|
||||
* higher number than the upper bound.
|
||||
*/
|
||||
static ItemDamageBound makeLowerBound(final ItemStack stack, final FuzzyMode fuzzy)
|
||||
{
|
||||
Preconditions.checkState( stack.getItem().isDamageable(), "Item#isDamageable() has to be true" );
|
||||
|
||||
int damage;
|
||||
if( fuzzy == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
if( stack.getMaxDamage() == 0 )
|
||||
{
|
||||
damage = stack.getItemDamage();
|
||||
}
|
||||
else
|
||||
{
|
||||
damage = stack.getMaxDamage();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final int breakpoint = fuzzy.calculateBreakPoint( stack.getMaxDamage() );
|
||||
damage = stack.getItemDamage() <= breakpoint ? breakpoint : stack.getMaxDamage();
|
||||
}
|
||||
|
||||
return new ItemDamageBound( damage );
|
||||
}
|
||||
|
||||
/*
|
||||
* Keep in mind that the stack order is from most damaged to least damaged, so this upper bound will actually be a
|
||||
* lower number than the lower bound. It also is exclusive.
|
||||
*/
|
||||
static ItemDamageBound makeUpperBound(final ItemStack stack, final FuzzyMode fuzzy) {
|
||||
Preconditions.checkState(stack.getItem().isDamageable(), "Item#isDamageable() has to be true");
|
||||
|
||||
int damage;
|
||||
if (fuzzy == FuzzyMode.IGNORE_ALL) {
|
||||
damage = MIN_DAMAGE_VALUE;
|
||||
} else {
|
||||
final int breakpoint = fuzzy.calculateBreakPoint(stack.getMaxDamage());
|
||||
damage = stack.getItemDamage() <= breakpoint ? MIN_DAMAGE_VALUE : breakpoint;
|
||||
}
|
||||
|
||||
return new ItemDamageBound(damage);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
* Copyright (c) 2013 - 2020, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
@@ -18,212 +18,196 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.Iterator;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.util.item.AESharedItemStack.Bounds;
|
||||
|
||||
public final class ItemList implements IItemList<IAEItemStack> {
|
||||
|
||||
public final class ItemList implements IItemList<IAEItemStack>
|
||||
{
|
||||
private final Reference2ObjectMap<Item, ItemVariantList> records = new Reference2ObjectOpenHashMap<>();
|
||||
/**
|
||||
* We increment this version field everytime an attempt to mutate this item list (or potentially one of its
|
||||
* sub-lists) is made. Iterators will copy the version when they are created and compare it against the current
|
||||
* version whenever they advance to trigger a {@link ConcurrentModificationException}.
|
||||
*/
|
||||
private final AtomicInteger version = new AtomicInteger(0);
|
||||
|
||||
private final NavigableMap<AESharedItemStack, IAEItemStack> records = new ConcurrentSkipListMap<>();
|
||||
@Override
|
||||
public IAEItemStack findPrecise(final IAEItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add( final IAEItemStack option )
|
||||
{
|
||||
if( option == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
ItemVariantList record = this.records.get(itemStack.getItem());
|
||||
return record != null ? record.findPrecise(itemStack) : null;
|
||||
}
|
||||
|
||||
final IAEItemStack st = this.records.get( ( (AEItemStack) option ).getSharedStack() );
|
||||
@Override
|
||||
public Collection<IAEItemStack> findFuzzy(final IAEItemStack filter, final FuzzyMode fuzzy) {
|
||||
if (filter == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
st.add( option );
|
||||
return;
|
||||
}
|
||||
ItemVariantList record = this.records.get(filter.getItem());
|
||||
return record != null ? record.findFuzzy(filter, fuzzy) : Collections.emptyList();
|
||||
}
|
||||
|
||||
final IAEItemStack opt = option.copy();
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
|
||||
this.putItemRecord( opt );
|
||||
}
|
||||
@Override
|
||||
public void add(final IAEItemStack itemStack) {
|
||||
version.incrementAndGet();
|
||||
|
||||
@Override
|
||||
public IAEItemStack findPrecise( final IAEItemStack itemStack )
|
||||
{
|
||||
if( itemStack == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
return this.records.get( ( (AEItemStack) itemStack ).getSharedStack() );
|
||||
}
|
||||
this.getOrCreateRecord(itemStack.getItem()).add(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IAEItemStack> findFuzzy( final IAEItemStack filter, final FuzzyMode fuzzy )
|
||||
{
|
||||
if( filter == null )
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@Override
|
||||
public void addStorage(final IAEItemStack itemStack) {
|
||||
version.incrementAndGet();
|
||||
|
||||
final AEItemStack ais = (AEItemStack) filter;
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
return ais.getOre().map( or ->
|
||||
{
|
||||
if( or.getAEEquivalents().size() == 1 )
|
||||
{
|
||||
final IAEItemStack is = or.getAEEquivalents().get( 0 );
|
||||
this.getOrCreateRecord(itemStack.getItem()).addStorage(itemStack);
|
||||
}
|
||||
|
||||
return this.findFuzzyDamage( is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
final Collection<IAEItemStack> output = new ArrayList<>();
|
||||
@Override
|
||||
public void addCrafting(final IAEItemStack itemStack) {
|
||||
version.incrementAndGet();
|
||||
|
||||
for( final IAEItemStack is : or.getAEEquivalents() )
|
||||
{
|
||||
output.addAll( this.findFuzzyDamage( is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) );
|
||||
}
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
} ).orElse( this.findFuzzyDamage( ais, fuzzy, false ) );
|
||||
}
|
||||
this.getOrCreateRecord(itemStack.getItem()).addCrafting(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
@Override
|
||||
public void addRequestable(final IAEItemStack itemStack) {
|
||||
version.incrementAndGet();
|
||||
|
||||
@Override
|
||||
public void addStorage( final IAEItemStack option )
|
||||
{
|
||||
if( option == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack st = this.records.get( ( (AEItemStack) option ).getSharedStack() );
|
||||
this.getOrCreateRecord(itemStack.getItem()).addRequestable(itemStack);
|
||||
}
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
st.incStackSize( option.getStackSize() );
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack getFirstItem() {
|
||||
for (final IAEItemStack stackType : this) {
|
||||
return stackType;
|
||||
}
|
||||
|
||||
final IAEItemStack opt = option.copy();
|
||||
return null;
|
||||
}
|
||||
|
||||
this.putItemRecord( opt );
|
||||
}
|
||||
@Override
|
||||
public int size() {
|
||||
int size = 0;
|
||||
for (ItemVariantList entry : records.values()) {
|
||||
size += entry.size();
|
||||
}
|
||||
|
||||
/*
|
||||
* public void clean() { Iterator<StackType> i = iterator(); while (i.hasNext()) { StackType AEI =
|
||||
* i.next(); if ( !AEI.isMeaningful() ) i.remove(); } }
|
||||
*/
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCrafting( final IAEItemStack option )
|
||||
{
|
||||
if( option == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public Iterator<IAEItemStack> iterator() {
|
||||
return new ChainedIterator(this.records.values().iterator(), version);
|
||||
}
|
||||
|
||||
final IAEItemStack st = this.records.get( ( (AEItemStack) option ).getSharedStack() );
|
||||
@Override
|
||||
public void resetStatus() {
|
||||
for (final IAEItemStack i : this) {
|
||||
i.reset();
|
||||
}
|
||||
}
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
st.setCraftable( true );
|
||||
return;
|
||||
}
|
||||
private ItemVariantList getOrCreateRecord(Item item) {
|
||||
return this.records.computeIfAbsent(item, this::makeRecordMap);
|
||||
}
|
||||
|
||||
final IAEItemStack opt = option.copy();
|
||||
opt.setStackSize( 0 );
|
||||
opt.setCraftable( true );
|
||||
private ItemVariantList makeRecordMap(Item item) {
|
||||
if (item.isDamageable()) {
|
||||
return new FuzzyItemVariantList();
|
||||
} else {
|
||||
return new NormalItemVariantList();
|
||||
}
|
||||
}
|
||||
|
||||
this.putItemRecord( opt );
|
||||
}
|
||||
/**
|
||||
* Iterates over multiple item lists as if they were one list.
|
||||
*/
|
||||
private static class ChainedIterator implements Iterator<IAEItemStack> {
|
||||
|
||||
@Override
|
||||
public void addRequestable( final IAEItemStack option )
|
||||
{
|
||||
if( option == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
private final AtomicInteger parentVersion;
|
||||
private final int version;
|
||||
private final Iterator<ItemVariantList> parent;
|
||||
private Iterator<IAEItemStack> next;
|
||||
|
||||
final IAEItemStack st = this.records.get( ( (AEItemStack) option ).getSharedStack() );
|
||||
public ChainedIterator(Iterator<ItemVariantList> iterator, AtomicInteger parentVersion) {
|
||||
this.parent = iterator;
|
||||
this.parentVersion = parentVersion;
|
||||
this.version = parentVersion.get();
|
||||
this.ensureItems();
|
||||
}
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
st.setCountRequestable( st.getCountRequestable() + option.getCountRequestable() );
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return next != null && next.hasNext();
|
||||
}
|
||||
|
||||
final IAEItemStack opt = option.copy();
|
||||
opt.setStackSize( 0 );
|
||||
opt.setCraftable( false );
|
||||
opt.setCountRequestable( option.getCountRequestable() );
|
||||
@Override
|
||||
public IAEItemStack next() {
|
||||
if (this.next == null) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
if (this.version != this.parentVersion.get()) {
|
||||
throw new ConcurrentModificationException();
|
||||
}
|
||||
|
||||
this.putItemRecord( opt );
|
||||
}
|
||||
IAEItemStack result = this.next.next();
|
||||
this.ensureItems();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack getFirstItem()
|
||||
{
|
||||
for( final IAEItemStack stackType : this )
|
||||
{
|
||||
return stackType;
|
||||
}
|
||||
private void ensureItems() {
|
||||
if (hasNext()) {
|
||||
return; // Still items left in the current one
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
// Find the next iterator willing to return some items...
|
||||
while (this.parent.hasNext()) {
|
||||
this.next = this.parent.next().iterator();
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return this.records.size();
|
||||
}
|
||||
if (this.next.hasNext()) {
|
||||
return; // Found one!
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IAEItemStack> iterator()
|
||||
{
|
||||
return new MeaningfulItemIterator<>( this.records.values().iterator() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetStatus()
|
||||
{
|
||||
for( final IAEItemStack i : this )
|
||||
{
|
||||
i.reset();
|
||||
}
|
||||
}
|
||||
|
||||
private IAEItemStack putItemRecord( final IAEItemStack itemStack )
|
||||
{
|
||||
return this.records.put( ( (AEItemStack) itemStack ).getSharedStack(), itemStack );
|
||||
}
|
||||
|
||||
private Collection<IAEItemStack> findFuzzyDamage( final IAEItemStack filter, final FuzzyMode fuzzy, final boolean ignoreMeta )
|
||||
{
|
||||
final AEItemStack itemStack = (AEItemStack) filter;
|
||||
final Bounds bounds = itemStack.getSharedStack().getBounds( fuzzy, ignoreMeta );
|
||||
|
||||
return this.records.subMap( bounds.lower(), true, bounds.upper(), true ).descendingMap().values();
|
||||
}
|
||||
// No more items
|
||||
this.next = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2021, TeamAppliedEnergistics, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
/**
|
||||
* Stores variants of a single type of {@link net.minecraft.item.Item}, i.e. versions with different durability, or
|
||||
* different NBT or capabilities.
|
||||
*/
|
||||
abstract class ItemVariantList {
|
||||
|
||||
public void add(final IAEItemStack option) {
|
||||
final IAEItemStack st = this.getRecords().get(((AEItemStack) option).getSharedStack());
|
||||
|
||||
if (st != null) {
|
||||
st.add(option);
|
||||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack opt = option.copy();
|
||||
|
||||
this.putItemRecord(opt);
|
||||
}
|
||||
|
||||
public IAEItemStack findPrecise(final IAEItemStack itemStack) {
|
||||
return this.getRecords().get(((AEItemStack) itemStack).getSharedStack());
|
||||
}
|
||||
|
||||
public void addStorage(final IAEItemStack option) {
|
||||
final IAEItemStack st = this.getRecords().get(((AEItemStack) option).getSharedStack());
|
||||
|
||||
if (st != null) {
|
||||
st.incStackSize(option.getStackSize());
|
||||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack opt = option.copy();
|
||||
|
||||
this.putItemRecord(opt);
|
||||
}
|
||||
|
||||
public void addCrafting(final IAEItemStack option) {
|
||||
final IAEItemStack st = this.getRecords().get(((AEItemStack) option).getSharedStack());
|
||||
|
||||
if (st != null) {
|
||||
st.setCraftable(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack opt = option.copy();
|
||||
opt.setStackSize(0);
|
||||
opt.setCraftable(true);
|
||||
|
||||
this.putItemRecord(opt);
|
||||
}
|
||||
|
||||
public void addRequestable(final IAEItemStack option) {
|
||||
final IAEItemStack st = this.getRecords().get(((AEItemStack) option).getSharedStack());
|
||||
|
||||
if (st != null) {
|
||||
st.setCountRequestable(st.getCountRequestable() + option.getCountRequestable());
|
||||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack opt = option.copy();
|
||||
opt.setStackSize(0);
|
||||
opt.setCraftable(false);
|
||||
opt.setCountRequestable(option.getCountRequestable());
|
||||
|
||||
this.putItemRecord(opt);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
int size = 0;
|
||||
for (IAEItemStack entry : getRecords().values()) {
|
||||
if (entry.isMeaningful()) {
|
||||
size++;
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
public Iterator<IAEItemStack> iterator() {
|
||||
return new MeaningfulItemIterator<>(this.getRecords().values());
|
||||
}
|
||||
|
||||
private void putItemRecord(final IAEItemStack itemStack) {
|
||||
this.getRecords().put(((AEItemStack) itemStack).getSharedStack(), itemStack);
|
||||
}
|
||||
|
||||
abstract Map<AESharedItemStack, IAEItemStack> getRecords();
|
||||
|
||||
public abstract Collection<IAEItemStack> findFuzzy(final IAEItemStack filter, final FuzzyMode fuzzy);
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
* Copyright (c) 2021, TeamAppliedEnergistics, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
@@ -18,59 +18,53 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
/**
|
||||
* This iterator will only return items from a collection that are meaningful (w.r.t.
|
||||
* {@link IAEItemStack#isMeaningful()}. Items that are not meaningful are automatically removed from the collection as
|
||||
* it is being iterated.
|
||||
*/
|
||||
public class MeaningfulItemIterator<T extends IAEItemStack> implements Iterator<T> {
|
||||
private final Iterator<T> parent;
|
||||
private T next;
|
||||
|
||||
public class MeaningfulItemIterator<T extends IAEItemStack> implements Iterator<T>
|
||||
{
|
||||
public MeaningfulItemIterator(final Collection<T> collection) {
|
||||
this.parent = collection.iterator();
|
||||
this.next = seekNext();
|
||||
}
|
||||
|
||||
private final Iterator<T> parent;
|
||||
private T next;
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.next != null;
|
||||
}
|
||||
|
||||
public MeaningfulItemIterator( final Iterator<T> iterator )
|
||||
{
|
||||
this.parent = iterator;
|
||||
}
|
||||
@Override
|
||||
public T next() {
|
||||
if (this.next == null) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
while( this.parent.hasNext() )
|
||||
{
|
||||
this.next = this.parent.next();
|
||||
T result = this.next;
|
||||
this.next = this.seekNext();
|
||||
return result;
|
||||
}
|
||||
|
||||
if( this.next.isMeaningful() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.parent.remove(); // self cleaning :3
|
||||
}
|
||||
}
|
||||
private T seekNext() {
|
||||
while (this.parent.hasNext()) {
|
||||
T item = this.parent.next();
|
||||
|
||||
this.next = null;
|
||||
return false;
|
||||
}
|
||||
if (item.isMeaningful()) {
|
||||
return item;
|
||||
} else {
|
||||
this.parent.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next()
|
||||
{
|
||||
if( this.next == null )
|
||||
{
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
return this.next;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
this.parent.remove();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2021, TeamAppliedEnergistics, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
/**
|
||||
* This variant list is optimized for items that cannot be damaged and thus do not support querying durability ranges
|
||||
* via {@link #findFuzzy(IAEItemStack, FuzzyMode)}.
|
||||
*/
|
||||
class NormalItemVariantList extends ItemVariantList {
|
||||
|
||||
private final Reference2ObjectMap<AESharedItemStack, IAEItemStack> records = new Reference2ObjectOpenHashMap<>();
|
||||
|
||||
@Override
|
||||
Map<AESharedItemStack, IAEItemStack> getRecords() {
|
||||
return this.records;
|
||||
}
|
||||
|
||||
/**
|
||||
* For items that do not support durability, we just return all variants to a fuzzy search.
|
||||
*/
|
||||
@Override
|
||||
public Collection<IAEItemStack> findFuzzy(IAEItemStack filter, FuzzyMode fuzzy) {
|
||||
return this.getRecords().values();
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -4,8 +4,8 @@
|
||||
"type": "forge:and",
|
||||
"values": [
|
||||
{
|
||||
"type": "minecraft:item_exists",
|
||||
"item": "appliedenergistics2:part:part.terminal"
|
||||
"type": "appliedenergistics2:part_exists",
|
||||
"part": "part.terminal"
|
||||
},
|
||||
{
|
||||
"type": "appliedenergistics2:material_exists",
|
||||
|
||||
Reference in New Issue
Block a user