Compare commits
64 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0bd2bd6b5a | |||
| db2c4c4325 | |||
| ac793ee847 | |||
| 6404f26cca | |||
| ced6ad865c | |||
| 24750f00b1 | |||
| df08ce0513 | |||
| f9c274fb48 | |||
| 3582582e3f | |||
| 6de48f8541 | |||
| 5a2c2d06d3 | |||
| 98d3cafdfd | |||
| 904de49543 | |||
| b0772bf94c | |||
| aa5d5e3623 | |||
| 42f4ef2855 | |||
| 3eb2582f29 | |||
| 307f86ded8 | |||
| 56f57e18a5 | |||
| eab695b692 | |||
| 0fb393820b | |||
| 01fe5c7a8b | |||
| 8468b47443 | |||
| 6cb583c918 | |||
| d69395a117 | |||
| 59effe8131 | |||
| 6f42876963 | |||
| 08952b48dd | |||
| e3c9c4ce65 | |||
| 7b91da58c0 | |||
| 26c06bca15 | |||
| 4458bd28ab | |||
| df3f00d978 | |||
| 18ae994ee4 | |||
| 47888b5546 | |||
| e18593feb5 | |||
| af4c3de55e | |||
| bea29331a3 | |||
| 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 |
@@ -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)
|
||||
@@ -3,7 +3,7 @@ aechannel=stable
|
||||
aebuild=7
|
||||
aegroup=appeng
|
||||
aebasename=appliedenergistics2
|
||||
trousers=omni-fixes-v21b
|
||||
trousers=omni-fixes-v45
|
||||
|
||||
#########################################################
|
||||
# Versions #
|
||||
|
||||
@@ -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,7 @@ configurations {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly "gregtechce:gregtech:1.12.2:1.12.0.662"
|
||||
compileOnly "gregtechce:gregtech:1.12.2:1.15.1.735"
|
||||
|
||||
// installable runtime dependencies
|
||||
mods "mcp.mobius.waila:Hwyla:${hwyla_version}"
|
||||
@@ -102,6 +97,7 @@ 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}"
|
||||
|
||||
@@ -46,7 +46,8 @@ public enum Upgrades
|
||||
*/
|
||||
FUZZY( 1 ),
|
||||
SPEED( 1 ),
|
||||
INVERTER( 1 );
|
||||
INVERTER( 1 ),
|
||||
PATTERN_EXPANSION(1);
|
||||
|
||||
private final int tier;
|
||||
private final Map<ItemStack, Integer> supportedMax = new HashMap<>();
|
||||
|
||||
@@ -89,6 +89,8 @@ public interface IMaterials
|
||||
|
||||
IItemDefinition cardCapacity();
|
||||
|
||||
IItemDefinition cardPatternExpansion();
|
||||
|
||||
IItemDefinition cardFuzzy();
|
||||
|
||||
IItemDefinition cardInverter();
|
||||
|
||||
@@ -31,6 +31,9 @@ import net.minecraft.world.World;
|
||||
import appeng.api.implementations.ICraftingPatternItem;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* do not implement provided by {@link ICraftingPatternItem}
|
||||
@@ -84,6 +87,11 @@ public interface ICraftingPatternDetails
|
||||
*/
|
||||
boolean canSubstitute();
|
||||
|
||||
default List<IAEItemStack> getSubstituteInputs( int slot )
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow using this INSTANCE of the pattern details to preform the crafting action with performance enhancements.
|
||||
*
|
||||
|
||||
@@ -44,11 +44,8 @@ public interface IStackWatcherHost
|
||||
/**
|
||||
* Called when a watched item changes amounts.
|
||||
*
|
||||
* @param o changed item list
|
||||
* @param fullStack old stack
|
||||
* @param diffStack new stack
|
||||
* @param src action source
|
||||
* @param chan storage channel
|
||||
*/
|
||||
void onStackChange( IItemList<?> o, IAEStack<?> fullStack, IAEStack<?> diffStack, IActionSource src, IStorageChannel<?> chan );
|
||||
void onStackChange( IAEStack<?> diffStack, IStorageChannel<?> chan );
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
@@ -50,7 +50,7 @@ public class GuiInterface extends GuiUpgradeable
|
||||
public GuiInterface( final InventoryPlayer inventoryPlayer, final IInterfaceHost te )
|
||||
{
|
||||
super( new ContainerInterface( inventoryPlayer, te ) );
|
||||
this.ySize = 211;
|
||||
this.ySize = 256;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -62,8 +62,7 @@ public class GuiInterface extends GuiUpgradeable
|
||||
this.BlockMode = new GuiImgButton( this.guiLeft - 18, this.guiTop + 8, Settings.BLOCK, YesNo.NO );
|
||||
this.buttonList.add( this.BlockMode );
|
||||
|
||||
this.interfaceMode = new GuiToggleButton( this.guiLeft - 18, this.guiTop + 26, 84, 85, GuiText.InterfaceTerminal
|
||||
.getLocal(), GuiText.InterfaceTerminalHint.getLocal() );
|
||||
this.interfaceMode = new GuiToggleButton( this.guiLeft - 18, this.guiTop + 26, 84, 85, GuiText.InterfaceTerminal.getLocal(), GuiText.InterfaceTerminalHint.getLocal() );
|
||||
this.buttonList.add( this.interfaceMode );
|
||||
}
|
||||
|
||||
@@ -86,13 +85,20 @@ public class GuiInterface extends GuiUpgradeable
|
||||
this.fontRenderer.drawString( GuiText.StoredItems.getLocal(), 8, 6 + 60 + 7, 4210752 );
|
||||
this.fontRenderer.drawString( GuiText.Patterns.getLocal(), 8, 6 + 73 + 7, 4210752 );
|
||||
|
||||
this.fontRenderer.drawString( GuiText.inventory.getLocal(), 8, this.ySize - 96 + 3, 4210752 );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBackground()
|
||||
{
|
||||
return "guis/interface.png";
|
||||
int upgrades = ( (ContainerInterface) this.cvb ).getPatternUpgrades();
|
||||
if( upgrades == 0 )
|
||||
{
|
||||
return "guis/newinterface.png";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "guis/newinterface" + upgrades + ".png";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -117,4 +123,5 @@ public class GuiInterface extends GuiUpgradeable
|
||||
NetworkHandler.instance().sendToServer( new PacketConfigButton( this.BlockMode.getSetting(), backwards ) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,13 @@ import java.util.*;
|
||||
|
||||
import appeng.api.config.ActionItems;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.client.gui.widgets.GuiImgButton;
|
||||
import appeng.core.worlddata.IWorldPlayerMapping;
|
||||
import appeng.helpers.DualityInterface;
|
||||
import appeng.parts.misc.PartInterface;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.misc.TileInterface;
|
||||
import appeng.util.BlockPosUtils;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
|
||||
@@ -49,6 +55,7 @@ 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;
|
||||
|
||||
|
||||
@@ -67,6 +74,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
private final HashMultimap<String, ClientDCInternalInv> byName = HashMultimap.create();
|
||||
private final HashMap<ClientDCInternalInv,BlockPos> blockPosHashMap = new HashMap<>();
|
||||
private final HashMap<GuiButton,ClientDCInternalInv> guiButtonHashMap = new HashMap<>();
|
||||
private final Map<ClientDCInternalInv,Integer> numUpgradesMap = new HashMap<>();
|
||||
private final ArrayList<String> names = new ArrayList<>();
|
||||
private final ArrayList<Object> lines = new ArrayList<>();
|
||||
private final Set<Object> matchedStacks = new HashSet<>();
|
||||
@@ -79,6 +87,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 )
|
||||
{
|
||||
@@ -88,7 +97,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
final GuiScrollbar scrollbar = new GuiScrollbar();
|
||||
this.setScrollBar( scrollbar );
|
||||
this.xSize = 208;
|
||||
this.ySize = 256;
|
||||
this.ySize = 255;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -133,36 +142,43 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
this.fontRenderer.drawString( this.getGuiDisplayName( GuiText.InterfaceTerminal.getLocal() ), 8, 6, 4210752 );
|
||||
this.fontRenderer.drawString( GuiText.inventory.getLocal(), this.offsetX + 2, this.ySize - 96 + 3, 4210752 );
|
||||
|
||||
final int ex = this.getScrollBar().getCurrentScroll();
|
||||
final int currentScroll = this.getScrollBar().getCurrentScroll();
|
||||
|
||||
this.guiButtonNextAssembler = new GuiImgButton(guiLeft + 123, guiTop + 25,Settings.ACTIONS, ActionItems.FREE_MOLECULAR_SLOT_SHORTCUT);
|
||||
this.guiButtonNextAssembler = new GuiImgButton( guiLeft + 123, guiTop + 25, Settings.ACTIONS, ActionItems.FREE_MOLECULAR_SLOT_SHORTCUT );
|
||||
this.buttonList.add( guiButtonNextAssembler );
|
||||
|
||||
guiButtonHide = new GuiImgButton( guiLeft + 141, guiTop + 25,Settings.ACTIONS, this.partInterfaceTerminal.onlyInterfacesWithFreeSlots ?
|
||||
ActionItems.TOGGLE_SHOW_FULL_INTERFACES_OFF :
|
||||
ActionItems.TOGGLE_SHOW_FULL_INTERFACES_ON);
|
||||
guiButtonHide = new GuiImgButton( guiLeft + 141, guiTop + 25, Settings.ACTIONS, this.partInterfaceTerminal.onlyInterfacesWithFreeSlots ? ActionItems.TOGGLE_SHOW_FULL_INTERFACES_OFF : ActionItems.TOGGLE_SHOW_FULL_INTERFACES_ON );
|
||||
this.buttonList.add( guiButtonHide );
|
||||
|
||||
this.inventorySlots.inventorySlots.removeIf( slot -> slot instanceof SlotDisconnected );
|
||||
|
||||
int offset = 51;
|
||||
for( int x = 0; x < LINES_ON_PAGE && ex + x < this.lines.size(); x++ )
|
||||
int offset = 52;
|
||||
int linesDraw = 0;
|
||||
for( int x = 0; x < LINES_ON_PAGE && linesDraw < LINES_ON_PAGE && currentScroll + x < this.lines.size(); x++ )
|
||||
{
|
||||
final Object lineObj = this.lines.get( ex + x );
|
||||
final Object lineObj = this.lines.get( currentScroll + x );
|
||||
if( lineObj instanceof ClientDCInternalInv )
|
||||
{
|
||||
final ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
|
||||
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);
|
||||
guiButtonHashMap.put( guiButton , inv);
|
||||
GuiButton guiButton = new GuiImgButton( guiLeft + 4, guiTop + offset, Settings.ACTIONS, ActionItems.HIGHLIGHT_INTERFACE );
|
||||
guiButtonHashMap.put( guiButton, inv );
|
||||
this.buttonList.add( guiButton );
|
||||
int extraLines = numUpgradesMap.get( inv );
|
||||
|
||||
for( int row = 0; row < 1 + extraLines && linesDraw < LINES_ON_PAGE ; ++row )
|
||||
{
|
||||
for( int z = 0; z < 9 ; z++ )
|
||||
{
|
||||
this.inventorySlots.inventorySlots.add( new SlotDisconnected( inv, z + ( row * 9 ), ( z * 18 + 22 ), offset ) );
|
||||
if( this.matchedStacks.contains( inv.getInventory().getStackInSlot( z + ( row * 9 ) ) ) )
|
||||
{
|
||||
drawRect( z * 18 + 22, offset, z * 18 + 22 + 16, offset + 16, 0x2A00FF00 );
|
||||
}
|
||||
}
|
||||
linesDraw++;
|
||||
offset += 18;
|
||||
}
|
||||
}
|
||||
else if( lineObj instanceof String )
|
||||
{
|
||||
@@ -173,17 +189,17 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
name = name + " (" + rows + ')';
|
||||
}
|
||||
|
||||
while( name.length() > 2 && this.fontRenderer.getStringWidth( name ) > 155 )
|
||||
while ( name.length() > 2 && this.fontRenderer.getStringWidth( name ) > 155 )
|
||||
{
|
||||
name = name.substring( 0, name.length() - 1 );
|
||||
}
|
||||
|
||||
this.fontRenderer.drawString( name, this.offsetX + 2, 6 + offset, 4210752 );
|
||||
this.fontRenderer.drawString( name, this.offsetX + 2, 5 + offset, 4210752 );
|
||||
linesDraw++;
|
||||
offset += 18;
|
||||
}
|
||||
offset += 18;
|
||||
}
|
||||
|
||||
if( searchFieldInputs.isMouseIn( mouseX , mouseY ) ) drawTooltip( Mouse.getEventX() * this.width / this.mc.displayWidth - offsetX, mouseY - guiTop, "Inputs OR names" );
|
||||
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" );
|
||||
|
||||
}
|
||||
@@ -217,9 +233,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();
|
||||
}
|
||||
|
||||
@@ -253,19 +277,28 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
|
||||
int offset = 51;
|
||||
final int ex = this.getScrollBar().getCurrentScroll();
|
||||
|
||||
for( int x = 0; x < LINES_ON_PAGE && ex + x < this.lines.size(); x++ )
|
||||
int linesDraw = 0;
|
||||
for( int x = 0; x < LINES_ON_PAGE && linesDraw < LINES_ON_PAGE && ex + x < this.lines.size(); x++ )
|
||||
{
|
||||
final Object lineObj = this.lines.get( ex + x );
|
||||
if( lineObj instanceof ClientDCInternalInv )
|
||||
{
|
||||
final ClientDCInternalInv inv = (ClientDCInternalInv) lineObj;
|
||||
|
||||
GlStateManager.color( 1, 1, 1, 1 );
|
||||
final int width = inv.getInventory().getSlots() * 18;
|
||||
this.drawTexturedModalRect( offsetX + 20, offsetY + offset, 20, 173, width, 18 );
|
||||
final int width = 9 * 18;
|
||||
|
||||
int extraLines = numUpgradesMap.get( lineObj );
|
||||
|
||||
for( int row = 0; row < 1 + extraLines && linesDraw < LINES_ON_PAGE; ++row )
|
||||
{
|
||||
this.drawTexturedModalRect( offsetX + 20, offsetY + offset , 20, 173, width, 18 );
|
||||
offset += 18;
|
||||
linesDraw++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
offset += 18;
|
||||
linesDraw++;
|
||||
}
|
||||
offset += 18;
|
||||
}
|
||||
|
||||
if( this.searchFieldInputs != null )
|
||||
@@ -325,6 +358,8 @@ 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" ));
|
||||
numUpgradesMap.put( current, invData.getInteger("numUpgrades"));
|
||||
|
||||
for( int x = 0; x < current.getInventory().getSlots(); x++ )
|
||||
{
|
||||
@@ -383,8 +418,12 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
// Search if the current inventory holds a pattern containing the search term.
|
||||
if( !found )
|
||||
{
|
||||
int slot = 0;
|
||||
for( final ItemStack itemStack : entry.getInventory() )
|
||||
{
|
||||
if (slot > 8 + numUpgradesMap.get(entry) * 9) {
|
||||
break;
|
||||
}
|
||||
if( !searchFieldInputs.isEmpty() && !searchFieldOutputs.isEmpty() ) {
|
||||
if (this.itemStackMatchesSearchTerm(itemStack, searchFieldInputs, 0) || this.itemStackMatchesSearchTerm(itemStack, searchFieldOutputs, 1)) {
|
||||
found = true;
|
||||
@@ -406,6 +445,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
// If only Interfaces with empty slots should be shown, check that here
|
||||
if(itemStack.isEmpty())
|
||||
interfaceHasFreeSlots = true;
|
||||
slot++;
|
||||
}
|
||||
}
|
||||
// if found, filter skipped or machine name matching the search term, add it
|
||||
@@ -446,7 +486,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
this.lines.addAll( clientInventories );
|
||||
}
|
||||
|
||||
this.getScrollBar().setRange( 0, this.lines.size() - LINES_ON_PAGE, 2 );
|
||||
this.getScrollBar().setRange( 0, this.lines.size() - 1, 1 );
|
||||
}
|
||||
|
||||
private boolean itemStackMatchesSearchTerm( final ItemStack itemStack, final String searchTerm,int pass )
|
||||
@@ -536,7 +576,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
||||
|
||||
if( o == null )
|
||||
{
|
||||
this.byId.put( id, o = new ClientDCInternalInv( 9, id, sortBy, string ) );
|
||||
this.byId.put( id, o = new ClientDCInternalInv( DualityInterface.NUMBER_OF_PATTERN_SLOTS, id, sortBy, string ) );
|
||||
this.refreshList = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -19,6 +19,9 @@
|
||||
package appeng.container.implementations;
|
||||
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.container.slot.*;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
@@ -26,14 +29,11 @@ import appeng.api.config.Settings;
|
||||
import appeng.api.config.YesNo;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.container.guisync.GuiSync;
|
||||
import appeng.container.slot.SlotFake;
|
||||
import appeng.container.slot.SlotNormal;
|
||||
import appeng.container.slot.SlotRestrictedInput;
|
||||
import appeng.helpers.DualityInterface;
|
||||
import appeng.helpers.IInterfaceHost;
|
||||
|
||||
|
||||
public class ContainerInterface extends ContainerUpgradeable
|
||||
public class ContainerInterface extends ContainerUpgradeable implements IOptionalSlotHost
|
||||
{
|
||||
|
||||
private final DualityInterface myDuality;
|
||||
@@ -44,16 +44,22 @@ public class ContainerInterface extends ContainerUpgradeable
|
||||
@GuiSync( 4 )
|
||||
public YesNo iTermMode = YesNo.YES;
|
||||
|
||||
@GuiSync( 7 )
|
||||
public int patternExpansions = 0;
|
||||
|
||||
public ContainerInterface( final InventoryPlayer ip, final IInterfaceHost te )
|
||||
{
|
||||
super( ip, te.getInterfaceDuality().getHost() );
|
||||
|
||||
this.myDuality = te.getInterfaceDuality();
|
||||
|
||||
for( int x = 0; x < DualityInterface.NUMBER_OF_PATTERN_SLOTS; x++ )
|
||||
for (int row = 0 ; row < 4 ; ++row)
|
||||
{
|
||||
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN, this.myDuality
|
||||
.getPatterns(), x, 8 + 18 * x, 90 + 7, this.getInventoryPlayer() ).setStackLimit( 1 ) );
|
||||
for( int x = 0; x < 9; x++ )
|
||||
{
|
||||
this.addSlotToContainer( new OptionalSlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ENCODED_PATTERN, this.myDuality
|
||||
.getPatterns(), this, x + row * 9, 8 + 18 * x, 97 + ( 18 * row ), row, this.getInventoryPlayer() ).setStackLimit( 1 ) );
|
||||
}
|
||||
}
|
||||
|
||||
for( int x = 0; x < DualityInterface.NUMBER_OF_CONFIG_SLOTS; x++ )
|
||||
@@ -70,7 +76,7 @@ public class ContainerInterface extends ContainerUpgradeable
|
||||
@Override
|
||||
protected int getHeight()
|
||||
{
|
||||
return 211;
|
||||
return 256;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,16 +88,35 @@ public class ContainerInterface extends ContainerUpgradeable
|
||||
@Override
|
||||
public int availableUpgrades()
|
||||
{
|
||||
return 1;
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSlotEnabled( final int idx )
|
||||
{
|
||||
return myDuality.getInstalledUpgrades(Upgrades.PATTERN_EXPANSION) >= idx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
this.verifyPermissions( SecurityPermissions.BUILD, false );
|
||||
|
||||
if (patternExpansions != getPatternUpgrades())
|
||||
{
|
||||
patternExpansions = getPatternUpgrades();
|
||||
this.myDuality.dropExcessPatterns();
|
||||
}
|
||||
super.detectAndSendChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate( final String field, final Object oldValue, final Object newValue ) {
|
||||
super.onUpdate(field, oldValue, newValue);
|
||||
if ( Platform.isClient() && field.equals("patternExpansions"))
|
||||
this.myDuality.dropExcessPatterns();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadSettingsFromHost( final IConfigManager cm )
|
||||
{
|
||||
@@ -118,4 +143,9 @@ public class ContainerInterface extends ContainerUpgradeable
|
||||
{
|
||||
this.iTermMode = iTermMode;
|
||||
}
|
||||
|
||||
public int getPatternUpgrades()
|
||||
{
|
||||
return this.myDuality.getInstalledUpgrades( Upgrades.PATTERN_EXPANSION );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -403,7 +404,9 @@ 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 );
|
||||
tag.setInteger( "numUpgrades", inv.numUpgrades );
|
||||
}
|
||||
|
||||
for( int x = 0; x < length; x++ )
|
||||
@@ -435,6 +438,8 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer
|
||||
private final IItemHandler client;
|
||||
private final IItemHandler server;
|
||||
private final BlockPos pos;
|
||||
private final int dim;
|
||||
private final int numUpgrades;
|
||||
|
||||
public InvTracker( final DualityInterface dual, final IItemHandler patterns, final String unlocalizedName )
|
||||
{
|
||||
@@ -443,6 +448,8 @@ 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();
|
||||
this.numUpgrades = dual.getInstalledUpgrades( Upgrades.PATTERN_EXPANSION);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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() )
|
||||
|
||||
@@ -157,7 +157,7 @@ public class AppEngSlot extends Slot
|
||||
{
|
||||
if( this.isSlotEnabled() )
|
||||
{
|
||||
return !this.itemHandler.extractItem( this.index, 1, true ).isEmpty();
|
||||
return !this.itemHandler.extractItem( this.index, Integer.MAX_VALUE, true ).isEmpty();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -363,6 +363,8 @@ final class Registration
|
||||
// Interface
|
||||
Upgrades.CRAFTING.registerItem( parts.iface(), 1 );
|
||||
Upgrades.CRAFTING.registerItem( blocks.iface(), 1 );
|
||||
Upgrades.PATTERN_EXPANSION.registerItem( parts.iface(), 3 );
|
||||
Upgrades.PATTERN_EXPANSION.registerItem( blocks.iface(), 3 );
|
||||
|
||||
// IO Port!
|
||||
Upgrades.SPEED.registerItem( blocks.iOPort(), 3 );
|
||||
|
||||
@@ -175,7 +175,7 @@ public class ApiStorage implements IStorageHelper
|
||||
@Override
|
||||
public int transferFactor()
|
||||
{
|
||||
return 125;
|
||||
return 1000;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -86,6 +86,7 @@ public final class ApiMaterials implements IMaterials
|
||||
private final IItemDefinition cardRedstone;
|
||||
private final IItemDefinition cardSpeed;
|
||||
private final IItemDefinition cardCapacity;
|
||||
private final IItemDefinition cardPatternExpansion;
|
||||
private final IItemDefinition cardFuzzy;
|
||||
private final IItemDefinition cardInverter;
|
||||
private final IItemDefinition cardCrafting;
|
||||
@@ -204,6 +205,7 @@ public final class ApiMaterials implements IMaterials
|
||||
this.cardRedstone = new DamagedItemDefinition( "material.card.redstone", materials.createMaterial( MaterialType.CARD_REDSTONE ) );
|
||||
this.cardSpeed = new DamagedItemDefinition( "material.card.acceleration", materials.createMaterial( MaterialType.CARD_SPEED ) );
|
||||
this.cardCapacity = new DamagedItemDefinition( "material.card.capacity", materials.createMaterial( MaterialType.CARD_CAPACITY ) );
|
||||
this.cardPatternExpansion = new DamagedItemDefinition( "material.card.pattern.expansion", materials.createMaterial(MaterialType.CARD_PATTERN_EXPANSION) );
|
||||
this.cardFuzzy = new DamagedItemDefinition( "material.card.fuzzy", materials.createMaterial( MaterialType.CARD_FUZZY ) );
|
||||
this.cardInverter = new DamagedItemDefinition( "material.card.inverter", materials.createMaterial( MaterialType.CARD_INVERTER ) );
|
||||
this.cardCrafting = new DamagedItemDefinition( "material.card.crafting", materials.createMaterial( MaterialType.CARD_CRAFTING ) );
|
||||
@@ -424,6 +426,9 @@ public final class ApiMaterials implements IMaterials
|
||||
return this.cardCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IItemDefinition cardPatternExpansion(){ return this.cardPatternExpansion;}
|
||||
|
||||
@Override
|
||||
public IItemDefinition cardFuzzy()
|
||||
{
|
||||
|
||||
@@ -20,6 +20,7 @@ package appeng.core.sync.packets;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.container.slot.IJEITargetSlot;
|
||||
@@ -224,7 +225,9 @@ public class PacketInventoryAction extends AppEngPacket
|
||||
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 ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.util.Iterator;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.container.implementations.ContainerPatternTerm;
|
||||
import gregtech.common.items.MetaTool;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
@@ -211,23 +212,21 @@ public class PacketJEIRecipe extends AppEngPacket
|
||||
out = Platform.poweredExtraction( energy, storage, request, cct.getActionSource() );
|
||||
if( out == null )
|
||||
{
|
||||
Collection<IAEItemStack> outList = inv.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ).getStorageList().findFuzzy( request, FuzzyMode.IGNORE_ALL );
|
||||
IAEItemStack mostDamaged = null;
|
||||
for( IAEItemStack is : outList )
|
||||
if( request.getItem().isDamageable() || ( Platform.isModLoaded( "gregtech" ) && request.getItem() instanceof MetaTool ) )
|
||||
{
|
||||
if( !is.isCraftable() && is.getItem().isDamageable() )
|
||||
Collection<IAEItemStack> outList = inv.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ).getStorageList().findFuzzy( request, FuzzyMode.IGNORE_ALL );
|
||||
for( IAEItemStack is : outList )
|
||||
{
|
||||
if( mostDamaged == null || mostDamaged.getItemDamage() < is.getItemDamage() )
|
||||
if( is.getDefinition().getMetadata() == request.getDefinition().getMetadata() )
|
||||
{
|
||||
mostDamaged = is;
|
||||
out = Platform.poweredExtraction( energy, storage, is.copy().setStackSize( 1 ), cct.getActionSource() );
|
||||
}
|
||||
if( out != null )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if( mostDamaged != null )
|
||||
{
|
||||
mostDamaged.setStackSize( 1 );
|
||||
out = Platform.poweredExtraction( energy, storage, mostDamaged, cct.getActionSource() );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -285,6 +284,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] );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ public class CraftingJob implements Runnable, ICraftingJob
|
||||
private final IItemList<IAEItemStack> missing = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
private final HashMap<String, TwoIntegers> opsAndMultiplier = new HashMap<>();
|
||||
private final Object monitor = new Object();
|
||||
private final Stopwatch watch = Stopwatch.createUnstarted();
|
||||
private CraftingTreeNode tree;
|
||||
private final IAEItemStack output;
|
||||
private boolean simulate = false;
|
||||
@@ -66,7 +67,10 @@ public class CraftingJob implements Runnable, ICraftingJob
|
||||
private long bytes = 0;
|
||||
private final IActionSource actionSrc;
|
||||
private final ICraftingCallback callback;
|
||||
private boolean running = false;
|
||||
private boolean done = false;
|
||||
private int time;
|
||||
private int incTime;
|
||||
|
||||
private World wrapWorld( final World w )
|
||||
{
|
||||
@@ -133,6 +137,7 @@ public class CraftingJob implements Runnable, ICraftingJob
|
||||
try
|
||||
{
|
||||
TickHandler.INSTANCE.registerCraftingSimulation( this.world, this );
|
||||
this.handlePausing();
|
||||
|
||||
final Stopwatch timer = Stopwatch.createStarted();
|
||||
|
||||
@@ -214,6 +219,41 @@ public class CraftingJob implements Runnable, ICraftingJob
|
||||
this.finish();
|
||||
}
|
||||
|
||||
void handlePausing() throws InterruptedException
|
||||
{
|
||||
if( !this.actionSrc.player().isPresent() && this.incTime > 100 )
|
||||
{
|
||||
this.incTime = 0;
|
||||
synchronized ( this.monitor )
|
||||
{
|
||||
if( this.watch.elapsed( TimeUnit.MICROSECONDS ) > this.time )
|
||||
{
|
||||
this.running = false;
|
||||
this.watch.stop();
|
||||
this.monitor.notify();
|
||||
}
|
||||
|
||||
if( !this.running )
|
||||
{
|
||||
AELog.craftingDebug( "crafting job will now sleep" );
|
||||
|
||||
while ( !this.running )
|
||||
{
|
||||
this.monitor.wait();
|
||||
}
|
||||
|
||||
AELog.craftingDebug( "crafting job now active" );
|
||||
}
|
||||
}
|
||||
|
||||
if( Thread.interrupted() )
|
||||
{
|
||||
throw new InterruptedException();
|
||||
}
|
||||
}
|
||||
this.incTime++;
|
||||
}
|
||||
|
||||
private void finish()
|
||||
{
|
||||
if( this.callback != null )
|
||||
@@ -225,6 +265,7 @@ public class CraftingJob implements Runnable, ICraftingJob
|
||||
|
||||
synchronized( this.monitor )
|
||||
{
|
||||
this.running = false;
|
||||
this.done = true;
|
||||
this.monitor.notify();
|
||||
}
|
||||
@@ -270,13 +311,25 @@ public class CraftingJob implements Runnable, ICraftingJob
|
||||
/**
|
||||
* @return true if this needs more simulation
|
||||
*/
|
||||
public boolean simulateFor()
|
||||
public boolean simulateFor(final int milli)
|
||||
{
|
||||
synchronized( this.monitor ) {
|
||||
if ( this.done ) {
|
||||
this.time = milli;
|
||||
|
||||
synchronized ( this.monitor )
|
||||
{
|
||||
if( this.done )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( !this.actionSrc.player().isPresent() )
|
||||
{
|
||||
this.watch.reset();
|
||||
this.watch.start();
|
||||
this.monitor.notify();
|
||||
}
|
||||
this.running = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ public class CraftingTreeNode
|
||||
|
||||
IAEItemStack request( final MECraftingInventory inv, long l, final IActionSource src ) throws CraftBranchFailure, InterruptedException
|
||||
{
|
||||
|
||||
this.job.handlePausing();
|
||||
final List<IAEItemStack> thingsUsed = new ArrayList<>();
|
||||
|
||||
this.what.setStackSize( l );
|
||||
@@ -130,7 +130,12 @@ public class CraftingTreeNode
|
||||
|
||||
if( this.parent.details.canSubstitute() )
|
||||
{
|
||||
itemList = inventoryList.findFuzzy( this.what, FuzzyMode.IGNORE_ALL );
|
||||
final List<IAEItemStack> substitutes = this.parent.details.getSubstituteInputs(this.slot);
|
||||
itemList = new ArrayList<>(substitutes.size());
|
||||
|
||||
for (IAEItemStack stack : substitutes) {
|
||||
itemList.addAll(inventoryList.findFuzzy(stack, FuzzyMode.IGNORE_ALL));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -185,7 +185,7 @@ public class CraftingTreeProcess
|
||||
|
||||
void request( final MECraftingInventory inv, final long i, final IActionSource src ) throws CraftBranchFailure, InterruptedException
|
||||
{
|
||||
|
||||
this.job.handlePausing();
|
||||
if( this.fullSimulation )
|
||||
{
|
||||
final InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||
@@ -305,7 +305,7 @@ public class CraftingTreeProcess
|
||||
|
||||
void getPlan( final IItemList<IAEItemStack> plan )
|
||||
{
|
||||
for( IAEItemStack i : this.details.getOutputs() )
|
||||
for( IAEItemStack i : this.details.getCondensedOutputs() )
|
||||
{
|
||||
i = i.copy();
|
||||
i.setCountRequestable( i.getStackSize() * this.crafts );
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ import java.nio.BufferOverflowException;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import appeng.container.slot.AppEngSlot;
|
||||
import appeng.container.slot.SlotPlayerHotBar;
|
||||
import appeng.container.slot.SlotPlayerInv;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
@@ -70,6 +73,7 @@ import appeng.me.helpers.ChannelPowerSrc;
|
||||
import appeng.util.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
|
||||
/**
|
||||
@@ -342,6 +346,89 @@ public class ContainerFluidTerminal extends AEBaseContainer implements IConfigMa
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack transferStackInSlot( final EntityPlayer p, final int idx )
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
EntityPlayerMP player = (EntityPlayerMP) p;
|
||||
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();
|
||||
|
||||
ItemStack copy = itemStack.copy();
|
||||
copy.setCount( 1 );
|
||||
IFluidHandlerItem fh = FluidUtil.getFluidHandler( copy );
|
||||
if( fh == null )
|
||||
{
|
||||
// only fluid handlers items
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
int heldAmount = itemStack.getCount();
|
||||
for( int i = 0; i < heldAmount; i++ )
|
||||
{
|
||||
copy = itemStack.copy();
|
||||
copy.setCount( 1 );
|
||||
fh = FluidUtil.getFluidHandler( copy );
|
||||
|
||||
final FluidStack extract = fh.drain( Integer.MAX_VALUE, false );
|
||||
if( extract == null || extract.amount < 1 )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
// Check if we can push into the system
|
||||
final IAEFluidStack notStorable = Platform.poweredInsert( this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack( extract ), this.getActionSource(), Actionable.SIMULATE );
|
||||
|
||||
if( notStorable != null && notStorable.getStackSize() > 0 )
|
||||
{
|
||||
final int toStore = (int) ( extract.amount - notStorable.getStackSize() );
|
||||
final FluidStack storable = fh.drain( toStore, false );
|
||||
|
||||
if( storable == null || storable.amount == 0 )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
else
|
||||
{
|
||||
extract.amount = storable.amount;
|
||||
}
|
||||
}
|
||||
|
||||
// Actually drain
|
||||
final FluidStack drained = fh.drain( extract, true );
|
||||
extract.amount = drained.amount;
|
||||
|
||||
final IAEFluidStack notInserted = Platform.poweredInsert( this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack( extract ), this.getActionSource() );
|
||||
|
||||
if( notInserted != null && notInserted.getStackSize() > 0 )
|
||||
{
|
||||
IAEFluidStack spill = this.monitor.injectItems( notInserted, Actionable.MODULATE, this.getActionSource() );
|
||||
if( spill != null && spill.getStackSize() > 0 )
|
||||
{
|
||||
fh.fill( spill.getFluidStack(), true );
|
||||
}
|
||||
}
|
||||
|
||||
if( notInserted == null )
|
||||
{
|
||||
if( !player.inventory.addItemStackToInventory( fh.getContainer() ) )
|
||||
{
|
||||
player.dropItem( fh.getContainer(), false );
|
||||
}
|
||||
clickSlot.decrStackSize( 1 );
|
||||
}
|
||||
}
|
||||
this.detectAndSendChanges();
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
return super.transferStackInSlot( p, idx );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAction( EntityPlayerMP player, InventoryAction action, int slot, long id )
|
||||
{
|
||||
@@ -352,13 +439,9 @@ public class ContainerFluidTerminal extends AEBaseContainer implements IConfigMa
|
||||
}
|
||||
|
||||
final ItemStack held = player.inventory.getItemStack();
|
||||
if( held.getCount() != 1 )
|
||||
{
|
||||
// only support stacksize 1 for now
|
||||
return;
|
||||
}
|
||||
|
||||
final IFluidHandlerItem fh = FluidUtil.getFluidHandler( held );
|
||||
ItemStack heldCopy = held.copy();
|
||||
heldCopy.setCount( 1 );
|
||||
IFluidHandlerItem fh = FluidUtil.getFluidHandler( heldCopy );
|
||||
if( fh == null )
|
||||
{
|
||||
// only fluid handlers items
|
||||
@@ -372,84 +455,122 @@ public class ContainerFluidTerminal extends AEBaseContainer implements IConfigMa
|
||||
// Check how much we can store in the item
|
||||
stack.setStackSize( Integer.MAX_VALUE );
|
||||
int amountAllowed = fh.fill( stack.getFluidStack(), false );
|
||||
stack.setStackSize( amountAllowed );
|
||||
|
||||
// Check if we can pull out of the system
|
||||
final IAEFluidStack canPull = Platform.poweredExtraction( this.getPowerSource(), this.monitor, stack, this.getActionSource(), Actionable.SIMULATE );
|
||||
if( canPull == null || canPull.getStackSize() < 1 )
|
||||
int heldAmount = held.getCount();
|
||||
for( int i = 0; i < heldAmount; i++ )
|
||||
{
|
||||
return;
|
||||
}
|
||||
ItemStack copiedFluidContainer = held.copy();
|
||||
copiedFluidContainer.setCount( 1 );
|
||||
fh = FluidUtil.getFluidHandler( copiedFluidContainer );
|
||||
|
||||
// How much could fit into the container
|
||||
final int canFill = fh.fill( canPull.getFluidStack(), false );
|
||||
if( canFill == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Now actually pull out of the system
|
||||
stack.setStackSize( canFill );
|
||||
final IAEFluidStack pulled = Platform.poweredExtraction( this.getPowerSource(), this.monitor, stack, this.getActionSource() );
|
||||
if( pulled == null || pulled.getStackSize() < 1 )
|
||||
{
|
||||
// Something went wrong
|
||||
AELog.error( "Unable to pull fluid out of the ME system even though the simulation said yes " );
|
||||
return;
|
||||
}
|
||||
|
||||
// Actually fill
|
||||
final int used = fh.fill( pulled.getFluidStack(), true );
|
||||
|
||||
if( used != canFill )
|
||||
{
|
||||
AELog.error( "Fluid item [%s] reported a different possible amount than it actually accepted.", held.getDisplayName() );
|
||||
}
|
||||
|
||||
player.inventory.setItemStack( fh.getContainer() );
|
||||
this.updateHeld( player );
|
||||
}
|
||||
else if( action == InventoryAction.EMPTY_ITEM )
|
||||
{
|
||||
// See how much we can drain from the item
|
||||
final FluidStack extract = fh.drain( Integer.MAX_VALUE, false );
|
||||
if( extract == null || extract.amount < 1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we can push into the system
|
||||
final IAEFluidStack notStorable = Platform.poweredInsert( this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack( extract ),
|
||||
this.getActionSource(), Actionable.SIMULATE );
|
||||
|
||||
if( notStorable != null && notStorable.getStackSize() > 0 )
|
||||
{
|
||||
final int toStore = (int) ( extract.amount - notStorable.getStackSize() );
|
||||
final FluidStack storable = fh.drain( toStore, false );
|
||||
|
||||
if( storable == null || storable.amount == 0 )
|
||||
// Check if we can pull out of the system
|
||||
final IAEFluidStack canPull = Platform.poweredExtraction( this.getPowerSource(), this.monitor, stack.setStackSize( amountAllowed ), this.getActionSource(), Actionable.SIMULATE );
|
||||
if( canPull == null || canPull.getStackSize() < 1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// How much could fit into the container
|
||||
final int canFill = fh.fill( canPull.getFluidStack(), false );
|
||||
if( canFill == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Now actually pull out of the system
|
||||
final IAEFluidStack pulled = Platform.poweredExtraction( this.getPowerSource(), this.monitor, stack.setStackSize( canFill ), this.getActionSource() );
|
||||
if( pulled == null || pulled.getStackSize() < 1 )
|
||||
{
|
||||
// Something went wrong
|
||||
AELog.error( "Unable to pull fluid out of the ME system even though the simulation said yes " );
|
||||
return;
|
||||
}
|
||||
|
||||
// Actually fill
|
||||
final int used = fh.fill( pulled.getFluidStack(), true );
|
||||
|
||||
if( used != canFill )
|
||||
{
|
||||
AELog.error( "Fluid item [%s] reported a different possible amount than it actually accepted.", held.getDisplayName() );
|
||||
}
|
||||
|
||||
if( held.getCount() == 1 )
|
||||
{
|
||||
player.inventory.setItemStack( fh.getContainer() );
|
||||
}
|
||||
else
|
||||
{
|
||||
extract.amount = storable.amount;
|
||||
player.inventory.getItemStack().shrink( 1 );
|
||||
if( !player.inventory.addItemStackToInventory( fh.getContainer() ) )
|
||||
{
|
||||
player.dropItem( fh.getContainer(), false );
|
||||
}
|
||||
}
|
||||
}
|
||||
this.updateHeld( player );
|
||||
|
||||
// Actually drain
|
||||
final FluidStack drained = fh.drain( extract, true );
|
||||
extract.amount = drained.amount;
|
||||
|
||||
final IAEFluidStack notInserted = Platform.poweredInsert( this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack( extract ),
|
||||
this.getActionSource() );
|
||||
|
||||
if( notInserted != null && notInserted.getStackSize() > 0 )
|
||||
}
|
||||
else if( action == InventoryAction.EMPTY_ITEM )
|
||||
{
|
||||
int heldAmount = held.getCount();
|
||||
for( int i = 0; i < heldAmount; i++ )
|
||||
{
|
||||
AELog.error( "Fluid item [%s] reported a different possible amount to drain than it actually provided.", held.getDisplayName() );
|
||||
}
|
||||
ItemStack copiedFluidContainer = held.copy();
|
||||
copiedFluidContainer.setCount( 1 );
|
||||
fh = FluidUtil.getFluidHandler( copiedFluidContainer );
|
||||
|
||||
player.inventory.setItemStack( fh.getContainer() );
|
||||
// See how much we can drain from the item
|
||||
final FluidStack extract = fh.drain( Integer.MAX_VALUE, false );
|
||||
if( extract == null || extract.amount < 1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we can push into the system
|
||||
final IAEFluidStack notStorable = Platform.poweredInsert( this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack( extract ), this.getActionSource(), Actionable.SIMULATE );
|
||||
|
||||
if( notStorable != null && notStorable.getStackSize() > 0 )
|
||||
{
|
||||
final int toStore = (int) ( extract.amount - notStorable.getStackSize() );
|
||||
final FluidStack storable = fh.drain( toStore, false );
|
||||
|
||||
if( storable == null || storable.amount == 0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
extract.amount = storable.amount;
|
||||
}
|
||||
}
|
||||
|
||||
// Actually drain
|
||||
final FluidStack drained = fh.drain( extract, true );
|
||||
extract.amount = drained.amount;
|
||||
|
||||
final IAEFluidStack notInserted = Platform.poweredInsert( this.getPowerSource(), this.monitor, AEFluidStack.fromFluidStack( extract ), this.getActionSource() );
|
||||
|
||||
if( notInserted != null && notInserted.getStackSize() > 0 )
|
||||
{
|
||||
IAEFluidStack spill = this.monitor.injectItems( notInserted, Actionable.MODULATE, this.getActionSource() );
|
||||
if( spill != null && spill.getStackSize() > 0 )
|
||||
{
|
||||
fh.fill( spill.getFluidStack(), true );
|
||||
}
|
||||
}
|
||||
|
||||
if( held.getCount() == 1 )
|
||||
{
|
||||
player.inventory.setItemStack( fh.getContainer() );
|
||||
}
|
||||
else
|
||||
{
|
||||
player.inventory.getItemStack().shrink( 1 );
|
||||
if( !player.inventory.addItemStackToInventory( fh.getContainer() ) )
|
||||
{
|
||||
player.dropItem( fh.getContainer(), false );
|
||||
}
|
||||
}
|
||||
}
|
||||
this.updateHeld( player );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ package appeng.fluids.parts;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -28,6 +27,7 @@ import java.util.Map;
|
||||
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.StorageFilter;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.misc.PartStorageBus;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
@@ -45,7 +45,6 @@ import appeng.api.storage.channels.IFluidStorageChannel;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.IGridProxyable;
|
||||
import appeng.me.storage.ITickingMonitor;
|
||||
|
||||
@@ -123,6 +122,7 @@ public class FluidHandlerAdapter implements IMEInventory<IAEFluidStack>, IBaseMo
|
||||
return null;
|
||||
}
|
||||
|
||||
IAEFluidStack gatheredAEFluidstack = AEFluidStack.fromFluidStack( gathered );
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
try
|
||||
@@ -134,7 +134,7 @@ public class FluidHandlerAdapter implements IMEInventory<IAEFluidStack>, IBaseMo
|
||||
// meh
|
||||
}
|
||||
}
|
||||
return AEFluidStack.fromFluidStack( gathered );
|
||||
return gatheredAEFluidstack;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -202,9 +202,9 @@ public class FluidHandlerAdapter implements IMEInventory<IAEFluidStack>, IBaseMo
|
||||
|
||||
private static class InventoryCache
|
||||
{
|
||||
private IAEFluidStack[] cachedAeStacks = new IAEFluidStack[0];
|
||||
private final IFluidHandler fluidHandler;
|
||||
private final StorageFilter mode;
|
||||
IItemList<IAEFluidStack> currentlyCached = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
|
||||
|
||||
public InventoryCache( IFluidHandler fluidHandler, StorageFilter mode )
|
||||
{
|
||||
@@ -216,19 +216,12 @@ public class FluidHandlerAdapter implements IMEInventory<IAEFluidStack>, IBaseMo
|
||||
{
|
||||
final List<IAEFluidStack> changes = new ArrayList<>();
|
||||
final IFluidTankProperties[] tankProperties = this.fluidHandler.getTankProperties();
|
||||
final int slots = tankProperties.length;
|
||||
|
||||
// Make room for new slots
|
||||
if( slots > this.cachedAeStacks.length )
|
||||
{
|
||||
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, slots );
|
||||
}
|
||||
IItemList<IAEFluidStack> currentlyOnStorage = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
|
||||
|
||||
for( int slot = 0; slot < slots; slot++ )
|
||||
for( IFluidTankProperties tankProperty : tankProperties )
|
||||
{
|
||||
// Save the old stuff
|
||||
final IAEFluidStack oldAEFS = this.cachedAeStacks[slot];
|
||||
FluidStack newFS = tankProperties[slot].getContents();
|
||||
FluidStack newFS = tankProperty.getContents();
|
||||
if( this.mode == StorageFilter.EXTRACTABLE_ONLY && newFS != null )
|
||||
{
|
||||
if( this.fluidHandler.drain( 1, false ) == null )
|
||||
@@ -236,82 +229,40 @@ public class FluidHandlerAdapter implements IMEInventory<IAEFluidStack>, IBaseMo
|
||||
newFS = null;
|
||||
}
|
||||
}
|
||||
this.handlePossibleSlotChanges( slot, oldAEFS, newFS, changes );
|
||||
}
|
||||
|
||||
// Handle cases where the number of slots actually is lower now than before
|
||||
if( slots < this.cachedAeStacks.length )
|
||||
{
|
||||
for( int slot = slots; slot < this.cachedAeStacks.length; slot++ )
|
||||
if( newFS != null )
|
||||
{
|
||||
final IAEFluidStack aeStack = this.cachedAeStacks[slot];
|
||||
|
||||
if( aeStack != null )
|
||||
{
|
||||
final IAEFluidStack a = aeStack.copy();
|
||||
a.setStackSize( -a.getStackSize() );
|
||||
changes.add( a );
|
||||
}
|
||||
currentlyOnStorage.add( AEFluidStack.fromFluidStack( newFS ) );
|
||||
}
|
||||
|
||||
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, slots );
|
||||
}
|
||||
|
||||
for ( final IAEFluidStack is : currentlyCached )
|
||||
{
|
||||
is.setStackSize( -is.getStackSize() );
|
||||
}
|
||||
|
||||
for ( final IAEFluidStack is : currentlyOnStorage )
|
||||
{
|
||||
currentlyCached.add( is );
|
||||
}
|
||||
|
||||
for ( final IAEFluidStack is : currentlyCached )
|
||||
{
|
||||
if( is.getStackSize() != 0 )
|
||||
{
|
||||
changes.add( is );
|
||||
}
|
||||
}
|
||||
|
||||
currentlyCached = currentlyOnStorage;
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
public IItemList<IAEFluidStack> getAvailableItems( IItemList<IAEFluidStack> out )
|
||||
{
|
||||
Arrays.stream( this.cachedAeStacks ).forEach( out::add );
|
||||
currentlyCached.iterator().forEachRemaining( out::add );
|
||||
return out;
|
||||
}
|
||||
|
||||
private void handlePossibleSlotChanges( int slot, IAEFluidStack oldAeFS, FluidStack newFS, List<IAEFluidStack> changes )
|
||||
{
|
||||
if( oldAeFS != null && oldAeFS.getFluidStack().isFluidEqual( newFS ) )
|
||||
{
|
||||
this.handleStackSizeChanged( slot, oldAeFS, newFS, changes );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.handleFluidChanged( slot, oldAeFS, newFS, changes );
|
||||
}
|
||||
}
|
||||
|
||||
private void handleStackSizeChanged( int slot, IAEFluidStack oldAeFS, FluidStack newFS, List<IAEFluidStack> changes )
|
||||
{
|
||||
// Still the same fluid, but amount might have changed
|
||||
final long diff = newFS.amount - oldAeFS.getStackSize();
|
||||
|
||||
if( diff != 0 )
|
||||
{
|
||||
final IAEFluidStack stack = oldAeFS.copy();
|
||||
stack.setStackSize( newFS.amount );
|
||||
|
||||
this.cachedAeStacks[slot] = stack;
|
||||
|
||||
final IAEFluidStack a = stack.copy();
|
||||
a.setStackSize( diff );
|
||||
changes.add( a );
|
||||
}
|
||||
}
|
||||
|
||||
private void handleFluidChanged( int slot, IAEFluidStack oldAeFS, FluidStack newFS, List<IAEFluidStack> changes )
|
||||
{
|
||||
// Completely different fluid
|
||||
this.cachedAeStacks[slot] = AEFluidStack.fromFluidStack( newFS );
|
||||
|
||||
// If we had a stack previously in this slot, notify the network about its disappearance
|
||||
if( oldAeFS != null )
|
||||
{
|
||||
oldAeFS.setStackSize( -oldAeFS.getStackSize() );
|
||||
changes.add( oldAeFS );
|
||||
}
|
||||
|
||||
// Notify the network about the new stack. Note that this is null if newFS was null
|
||||
if( this.cachedAeStacks[slot] != null )
|
||||
{
|
||||
changes.add( this.cachedAeStacks[slot] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ public class PartFluidFormationPlane extends PartAbstractFormationPlane<IAEFluid
|
||||
@Override
|
||||
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
|
||||
{
|
||||
if( this.getProxy().isActive() && channel == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) )
|
||||
if( channel == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) )
|
||||
{
|
||||
final List<IMEInventoryHandler> handler = new ArrayList<>( 1 );
|
||||
handler.add( this.myHandler );
|
||||
|
||||
@@ -4,7 +4,9 @@ package appeng.fluids.parts;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import appeng.api.networking.events.MENetworkChannelChanged;
|
||||
import appeng.fluids.helper.IConfigurableFluidInventory;
|
||||
import appeng.me.cache.NetworkMonitor;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -34,7 +36,6 @@ import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IFluidStorageChannel;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.api.util.IConfigManager;
|
||||
@@ -112,11 +113,11 @@ public class PartFluidLevelEmitter extends PartUpgradeable implements IStackWatc
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStackChange( IItemList<?> o, IAEStack<?> fullStack, IAEStack<?> diffStack, IActionSource src, IStorageChannel<?> chan )
|
||||
public void onStackChange( IAEStack<?> diffStack, IStorageChannel<?> chan )
|
||||
{
|
||||
if( chan == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) && fullStack.equals( this.config.getFluidInSlot( 0 ) ) )
|
||||
if( chan == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) && diffStack.equals( this.config.getFluidInSlot( 0 ) ) )
|
||||
{
|
||||
this.lastReportedValue = fullStack.getStackSize();
|
||||
this.lastReportedValue += diffStack.getStackSize();
|
||||
this.updateState();
|
||||
}
|
||||
}
|
||||
@@ -128,14 +129,22 @@ public class PartFluidLevelEmitter extends PartUpgradeable implements IStackWatc
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void channelChanged( final MENetworkChannelsChanged c )
|
||||
public void powerStatusChange( final MENetworkPowerStatusChange powerEvent )
|
||||
{
|
||||
if (this.getProxy().isActive())
|
||||
{
|
||||
onListUpdate();
|
||||
}
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerChanged( final MENetworkPowerStatusChange c )
|
||||
public void channelChanged( final MENetworkChannelsChanged c )
|
||||
{
|
||||
if (this.getProxy().isActive())
|
||||
{
|
||||
onListUpdate();
|
||||
}
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@@ -247,10 +256,9 @@ public class PartFluidLevelEmitter extends PartUpgradeable implements IStackWatc
|
||||
|
||||
if( myStack == null )
|
||||
{
|
||||
this.lastReportedValue = 0;
|
||||
for( final IAEFluidStack st : monitor.getStorageList() )
|
||||
if( monitor instanceof NetworkMonitor )
|
||||
{
|
||||
this.lastReportedValue += st.getStackSize();
|
||||
this.lastReportedValue = ( (NetworkMonitor<IAEFluidStack>) monitor ).getGridCurrentCount();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -268,12 +268,9 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
|
||||
{
|
||||
if( this.getProxy().isActive() )
|
||||
{
|
||||
this.getProxy()
|
||||
.getStorage()
|
||||
.postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ), change, this.source );
|
||||
this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ), change, this.source );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
} catch ( final GridAccessException e )
|
||||
{
|
||||
// :(
|
||||
}
|
||||
@@ -414,7 +411,7 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
|
||||
{
|
||||
if( channel == this.getStorageChannel() )
|
||||
{
|
||||
final IMEInventoryHandler<IAEFluidStack> out = this.getProxy().isActive() ? this.getInternalHandler() : null;
|
||||
final IMEInventoryHandler<IAEFluidStack> out = this.getInternalHandler();
|
||||
if( out != null )
|
||||
{
|
||||
return Collections.singletonList( out );
|
||||
|
||||
@@ -20,19 +20,22 @@ package appeng.helpers;
|
||||
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
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 net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -107,9 +110,11 @@ import static gregtech.api.block.machines.BlockMachine.getMetaTileEntity;
|
||||
|
||||
public class DualityInterface implements IGridTickable, IStorageMonitorable, IInventoryDestination, IAEAppEngInventory, IConfigManagerHost, ICraftingProvider, IUpgradeableHost
|
||||
{
|
||||
private int[] failedCraftTriesSlot = {0,0,0,0,0,0,0,0,0};
|
||||
|
||||
public static final int NUMBER_OF_STORAGE_SLOTS = 9;
|
||||
public static final int NUMBER_OF_CONFIG_SLOTS = 9;
|
||||
public static final int NUMBER_OF_PATTERN_SLOTS = 9;
|
||||
public static final int NUMBER_OF_PATTERN_SLOTS = 36;
|
||||
|
||||
private static final Collection<Block> BAD_BLOCKS = new HashSet<>( 100 );
|
||||
private final IAEItemStack[] requireWork = { null, null, null, null, null, null, null, null, null };
|
||||
@@ -145,7 +150,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
this.gridProxy = networkProxy;
|
||||
this.gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||
|
||||
this.upgrades = new StackUpgradeInventory( this.gridProxy.getMachineRepresentation(), this, 1 );
|
||||
this.upgrades = new StackUpgradeInventory( this.gridProxy.getMachineRepresentation(), this, 4);
|
||||
this.cm.registerSetting( Settings.BLOCK, YesNo.NO );
|
||||
this.cm.registerSetting( Settings.INTERFACE_TERMINAL, YesNo.YES );
|
||||
|
||||
@@ -173,7 +178,6 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if( inv == this.config )
|
||||
{
|
||||
this.readConfig();
|
||||
@@ -273,10 +277,11 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
}
|
||||
|
||||
this.waitingToSendFacing = null;
|
||||
final NBTTagCompound waitingListSided = data.getCompoundTag("sidedWaitList");
|
||||
final NBTTagCompound waitingListSided = data.getCompoundTag( "sidedWaitList" );
|
||||
|
||||
for (EnumFacing s : EnumFacing.values())
|
||||
if (waitingListSided.hasKey( s.name() )) {
|
||||
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++ )
|
||||
{
|
||||
@@ -284,14 +289,31 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
if( c != null )
|
||||
{
|
||||
final ItemStack is = new ItemStack( c );
|
||||
this.addToSendListFacing( is , EnumFacing.getFront( s.getIndex() ) );
|
||||
this.addToSendListFacing( is, EnumFacing.getFront( s.getIndex() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.craftingTracker.readFromNBT( data );
|
||||
|
||||
// fix upgrade slot size mismatch
|
||||
NBTTagCompound up = data.getCompoundTag( "upgrades" );
|
||||
if( up.hasKey( "Size" ) && up.getInteger( "Size" ) != this.upgrades.getSlots() )
|
||||
{
|
||||
up.setInteger( "Size", this.upgrades.getSlots() );
|
||||
this.upgrades.writeToNBT( up, "upgrades" );
|
||||
}
|
||||
|
||||
this.upgrades.readFromNBT( data, "upgrades" );
|
||||
this.config.readFromNBT( data, "config" );
|
||||
|
||||
NBTTagCompound pa = data.getCompoundTag( "patterns" );
|
||||
if( pa.hasKey( "Size" ) && pa.getInteger( "Size" ) != this.patterns.getSlots() )
|
||||
{
|
||||
pa.setInteger( "Size", this.patterns.getSlots() );
|
||||
this.upgrades.writeToNBT( pa, "patterns" );
|
||||
}
|
||||
|
||||
this.patterns.readFromNBT( data, "patterns" );
|
||||
this.storage.readFromNBT( data, "storage" );
|
||||
this.priority = data.getInteger( "priority" );
|
||||
@@ -394,9 +416,8 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
|
||||
private void updateCraftingList()
|
||||
{
|
||||
final Boolean[] accountedFor = { false, false, false, false, false, false, false, false, false }; // 9...
|
||||
|
||||
assert ( accountedFor.length == this.patterns.getSlots() );
|
||||
final Boolean[] accountedFor = new Boolean[this.patterns.getSlots()];
|
||||
Arrays.fill( accountedFor, false );
|
||||
|
||||
if( !this.gridProxy.isReady() )
|
||||
{
|
||||
@@ -411,7 +432,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
final ICraftingPatternDetails details = i.next();
|
||||
boolean found = false;
|
||||
|
||||
for( int x = 0; x < accountedFor.length; x++ )
|
||||
for( int x = 0; x < accountedFor.length ; x++ )
|
||||
{
|
||||
final ItemStack is = this.patterns.getStackInSlot( x );
|
||||
if( details.getPattern() == is )
|
||||
@@ -427,7 +448,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
}
|
||||
}
|
||||
|
||||
for( int x = 0; x < accountedFor.length; x++ )
|
||||
for( int x = 0; x < accountedFor.length ; x++ )
|
||||
{
|
||||
if( !accountedFor[x] )
|
||||
{
|
||||
@@ -580,6 +601,30 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
return false;
|
||||
}
|
||||
|
||||
public void dropExcessPatterns()
|
||||
{
|
||||
IItemHandler patterns = getPatterns();
|
||||
|
||||
List<ItemStack> dropList = new ArrayList<>();
|
||||
for( int invSlot = 0; invSlot < patterns.getSlots(); invSlot++ )
|
||||
{
|
||||
if( invSlot > 8 + this.getInstalledUpgrades( Upgrades.PATTERN_EXPANSION ) * 9 )
|
||||
{
|
||||
ItemStack is = patterns.getStackInSlot( invSlot );
|
||||
if( is.isEmpty() ) continue;
|
||||
dropList.add( patterns.extractItem( invSlot, Integer.MAX_VALUE, false ) );
|
||||
}
|
||||
}
|
||||
if( dropList.size() > 0 )
|
||||
{
|
||||
World world = this.getLocation().getWorld();
|
||||
BlockPos blockPos = this.getLocation().getPos();
|
||||
Platform.spawnDrops( world, blockPos, dropList );
|
||||
}
|
||||
|
||||
this.gridProxy.setIdlePowerUsage( Math.pow( 4, ( this.getInstalledUpgrades( Upgrades.PATTERN_EXPANSION ) ) ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert( final ItemStack stack )
|
||||
{
|
||||
@@ -886,8 +931,17 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
{
|
||||
if( this.getInstalledUpgrades( Upgrades.CRAFTING ) > 0 && itemStack != null )
|
||||
{
|
||||
return this.craftingTracker.handleCrafting( x, itemStack.getStackSize(), itemStack, d, this.iHost.getTileEntity().getWorld(),
|
||||
if (this.failedCraftTriesSlot[x] <= 0)
|
||||
{
|
||||
boolean crafted = this.craftingTracker.handleCrafting( x, itemStack.getStackSize(), itemStack, d, this.iHost.getTileEntity().getWorld(),
|
||||
this.gridProxy.getGrid(), this.gridProxy.getCrafting(), this.mySource );
|
||||
|
||||
if (crafted) this.failedCraftTriesSlot[x] = 0;
|
||||
else{
|
||||
this.failedCraftTriesSlot[x] += 2;
|
||||
}
|
||||
}
|
||||
this.failedCraftTriesSlot[x] -= 1;
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
@@ -1082,26 +1136,40 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor( te, s.getOpposite() );
|
||||
if( ad != null )
|
||||
{
|
||||
boolean isDrawer = te.getBlockType().getRegistryName().getResourceDomain().equals( "storagedrawers" );
|
||||
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 if ( invIsBlocked( ad ) )
|
||||
|
||||
else if( invIsBlocked( ad ) )
|
||||
{
|
||||
visitedFaces.remove( s );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if( this.acceptsItems( ad, patternDetails, isDrawer ) )
|
||||
if( this.acceptsItems( ad, table ) )
|
||||
{
|
||||
visitedFaces.remove( s );
|
||||
for( int x = 0; x < table.getSizeInventory(); x++ )
|
||||
@@ -1142,19 +1210,34 @@ 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;
|
||||
@@ -1167,6 +1250,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();
|
||||
@@ -1177,75 +1266,23 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
||||
return this.cm.getSetting( Settings.BLOCK ) == YesNo.YES;
|
||||
}
|
||||
|
||||
private boolean acceptsItems( final InventoryAdaptor ad, final ICraftingPatternDetails patternDetails, boolean isDrawer )
|
||||
private boolean acceptsItems( final InventoryAdaptor ad, final InventoryCrafting table )
|
||||
{
|
||||
List<ItemStack> patternedStacks = Arrays.stream( patternDetails.getCondensedInputs() ).map( IAEItemStack::createItemStack ).collect( Collectors.toList() );
|
||||
List<ItemSlot> copiedItemSlots = new ArrayList<>();
|
||||
|
||||
if( patternedStacks.size() == 1 )
|
||||
for( int x = 0; x < table.getSizeInventory(); x++ )
|
||||
{
|
||||
return ad.simulateAdd( patternedStacks.get( 0 ) ).isEmpty();
|
||||
}
|
||||
else
|
||||
{
|
||||
for ( ItemSlot itemSlot : ad )
|
||||
final ItemStack is = table.getStackInSlot( x );
|
||||
if( is.isEmpty() )
|
||||
{
|
||||
//skip storage drawers slot 0 to avoid voiding items due to broken itemhandler implementation
|
||||
if( isDrawer && itemSlot.getSlot() == 0 ){
|
||||
continue;
|
||||
}
|
||||
//some inventory may expose their special slots ( for upgrades, etc )
|
||||
//if its empty AND we cant fit any of the items in the recipes, skip it.
|
||||
ItemStack stackInSlot = itemSlot.getItemStack();
|
||||
for ( IAEItemStack aeItemStack : patternDetails.getCondensedInputs() )
|
||||
{
|
||||
if( stackInSlot.isEmpty() )
|
||||
{
|
||||
if( itemSlot.simulateInsertItem( aeItemStack.getDefinition() ).isEmpty() )
|
||||
{
|
||||
copiedItemSlots.add( itemSlot.copy() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
// copy partially filled slots for merging logic
|
||||
else if( stackInSlot.getCount() < Math.min( itemSlot.getSlotLimit(), stackInSlot.getMaxStackSize() ) )
|
||||
{
|
||||
if( aeItemStack.isSameType( stackInSlot ) )
|
||||
{
|
||||
copiedItemSlots.add( itemSlot.copy() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// start merging in order of slots, left to right.
|
||||
for ( ItemSlot copiedItemSlot : copiedItemSlots )
|
||||
if( !ad.simulateAdd( is.copy() ).isEmpty() )
|
||||
{
|
||||
Iterator<ItemStack> patStackIterator = patternedStacks.iterator();
|
||||
while ( patStackIterator.hasNext() )
|
||||
{
|
||||
ItemStack patStack = patStackIterator.next();
|
||||
ItemStack remainder = copiedItemSlot.simulateInsertItem( patStack );
|
||||
|
||||
if( !remainder.isEmpty() )
|
||||
{
|
||||
patStack.setCount( patStack.getCount() - ( patStack.getCount() - remainder.getCount() ) );
|
||||
}
|
||||
else //entire stack got injected
|
||||
{
|
||||
patStackIterator.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if we merged EVERYTHING successfully , return true.
|
||||
if( patternedStacks.size() == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -62,6 +62,7 @@ public class HighlighterHandler
|
||||
tessellator.draw();
|
||||
|
||||
GlStateManager.enableTexture2D();
|
||||
GlStateManager.enableDepth();
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,21 +19,18 @@
|
||||
package appeng.helpers;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
@@ -46,11 +43,17 @@ import appeng.core.AELog;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import net.minecraftforge.common.crafting.IShapedRecipe;
|
||||
|
||||
|
||||
public class PatternHelper implements ICraftingPatternDetails, Comparable<PatternHelper>
|
||||
{
|
||||
|
||||
private static final int CRAFTING_GRID_DIMENSION = 3;
|
||||
private static final int ALL_INPUT_LIMIT = CRAFTING_GRID_DIMENSION * CRAFTING_GRID_DIMENSION;
|
||||
private static final int CRAFTING_OUTPUT_LIMIT = 1;
|
||||
private static final int PROCESSING_OUTPUT_LIMIT = 3;
|
||||
|
||||
private final ItemStack patternItem;
|
||||
private final InventoryCrafting crafting = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||
private final InventoryCrafting testFrame = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||
@@ -60,6 +63,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
private final IAEItemStack[] condensedOutputs;
|
||||
private final IAEItemStack[] inputs;
|
||||
private final IAEItemStack[] outputs;
|
||||
private final Map<Integer, List<IAEItemStack>> substituteInputs;
|
||||
private final boolean isCrafting;
|
||||
private final boolean canSubstitute;
|
||||
private final Set<TestLookup> failCache = new HashSet<>();
|
||||
@@ -143,9 +147,11 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
}
|
||||
}
|
||||
}
|
||||
final int outputLength = this.isCrafting ? CRAFTING_OUTPUT_LIMIT : PROCESSING_OUTPUT_LIMIT;
|
||||
|
||||
this.outputs = out.toArray( new IAEItemStack[out.size()] );
|
||||
this.inputs = in.toArray( new IAEItemStack[in.size()] );
|
||||
this.inputs = in.toArray(new IAEItemStack[ALL_INPUT_LIMIT]);
|
||||
this.outputs = out.toArray(new IAEItemStack[outputLength]);
|
||||
this.substituteInputs = new HashMap<>(ALL_INPUT_LIMIT);
|
||||
|
||||
final Map<IAEItemStack, IAEItemStack> tmpOutputs = new HashMap<>();
|
||||
|
||||
@@ -257,6 +263,14 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
|
||||
this.testFrame.setInventorySlotContents( slotIndex, i );
|
||||
|
||||
// If we cannot substitute, the items must match exactly
|
||||
if (!canSubstitute && slotIndex < inputs.length) {
|
||||
if (!inputs[slotIndex].isSameType(i)) {
|
||||
this.markItemAs(slotIndex, i, TestStatus.DECLINE);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if( this.standardRecipe.matches( this.testFrame, w ) )
|
||||
{
|
||||
final ItemStack testOutput = this.standardRecipe.getCraftingResult( this.testFrame );
|
||||
@@ -268,25 +282,6 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if( AEConfig.instance().isFeatureEnabled( AEFeature.CRAFTING_MANAGER_FALLBACK ) )
|
||||
{
|
||||
final ItemStack testOutput = CraftingManager.findMatchingResult( this.testFrame, w );
|
||||
|
||||
if( Platform.itemComparisons().isSameItem( this.correctOutput, testOutput ) )
|
||||
{
|
||||
this.testFrame.setInventorySlotContents( slotIndex, this.crafting.getStackInSlot( slotIndex ) );
|
||||
this.markItemAs( slotIndex, i, TestStatus.ACCEPT );
|
||||
|
||||
if( AELog.isCraftingDebugLogEnabled() )
|
||||
{
|
||||
this.warnAboutCraftingManager( true );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
this.warnAboutCraftingManager( false );
|
||||
}
|
||||
|
||||
this.markItemAs( slotIndex, i, TestStatus.DECLINE );
|
||||
return false;
|
||||
@@ -328,6 +323,97 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
return this.canSubstitute;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IAEItemStack> getSubstituteInputs(int slot) {
|
||||
if (this.inputs[slot] == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return this.substituteInputs.computeIfAbsent(slot, value -> {
|
||||
ItemStack[] matchingStacks = getRecipeIngredient(slot).getMatchingStacks();
|
||||
List<IAEItemStack> itemList = new ArrayList<>(matchingStacks.length + 1);
|
||||
for (ItemStack matchingStack : matchingStacks) {
|
||||
itemList.add(AEItemStack.fromItemStack(matchingStack));
|
||||
}
|
||||
|
||||
// Ensure that the specific item put in by the user is at the beginning,
|
||||
// so that it takes precedence over substitutions
|
||||
itemList.add(0, this.inputs[slot]);
|
||||
return itemList;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link Ingredient} from the actual used recipe for a given slot-index into {@link #getInputs()}.
|
||||
* <p/>
|
||||
* Conversion is needed for two reasons: our sparse ingredients are always organized in a 3x3 grid, while Vanilla's
|
||||
* ingredient list will be condensed to the actual recipe's grid size. In addition, in our 3x3 grid, the user can
|
||||
* shift the actual recipe input to the right and down.
|
||||
*/
|
||||
private Ingredient getRecipeIngredient(int slot) {
|
||||
|
||||
if (standardRecipe instanceof IShapedRecipe ) {
|
||||
IShapedRecipe shapedRecipe = (IShapedRecipe) standardRecipe;
|
||||
|
||||
return getShapedRecipeIngredient(slot, shapedRecipe.getRecipeWidth());
|
||||
} else {
|
||||
return getShapelessRecipeIngredient(slot);
|
||||
}
|
||||
}
|
||||
|
||||
private Ingredient getShapedRecipeIngredient(int slot, int recipeWidth) {
|
||||
// Compute the offset of the user's input vs. crafting grid origin
|
||||
// Which is >0 if they have empty rows above or to the left of their input
|
||||
int topOffset = 0;
|
||||
if (inputs[0] == null && inputs[1] == null && inputs[2] == null) {
|
||||
topOffset++; // First row is fully empty
|
||||
if (inputs[3] == null && inputs[4] == null && inputs[5] == null) {
|
||||
topOffset++; // Second row is fully empty
|
||||
}
|
||||
}
|
||||
int leftOffset = 0;
|
||||
if (inputs[0] == null && inputs[3] == null && inputs[6] == null) {
|
||||
leftOffset++; // First column is fully empty
|
||||
if (inputs[1] == null && inputs[4] == null && inputs[7] == null) {
|
||||
leftOffset++; // Second column is fully empty
|
||||
}
|
||||
}
|
||||
|
||||
// Compute the x,y of the slot, as-if the recipe was anchored to 0,0
|
||||
int slotX = slot % CRAFTING_GRID_DIMENSION - leftOffset;
|
||||
int slotY = slot / CRAFTING_GRID_DIMENSION - topOffset;
|
||||
|
||||
// Compute the index into the recipe's ingredient list now
|
||||
int ingredientIndex = slotY * recipeWidth + slotX;
|
||||
|
||||
NonNullList<Ingredient> ingredients = standardRecipe.getIngredients();
|
||||
|
||||
if (ingredientIndex < 0 || ingredientIndex > ingredients.size()) {
|
||||
return Ingredient.EMPTY;
|
||||
}
|
||||
|
||||
return ingredients.get(ingredientIndex);
|
||||
}
|
||||
|
||||
private Ingredient getShapelessRecipeIngredient(int slot) {
|
||||
// We map the list of *filled* sparse inputs to the shapeless (ergo unordered)
|
||||
// ingredients. While these do not actually correspond to each other,
|
||||
// since both lists have the same length, the mapping is at least stable.
|
||||
int ingredientIndex = 0;
|
||||
for (int i = 0; i < slot; i++) {
|
||||
if (inputs[i] != null) {
|
||||
ingredientIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
NonNullList<Ingredient> ingredients = standardRecipe.getIngredients();
|
||||
if (ingredientIndex < ingredients.size()) {
|
||||
return ingredients.get(ingredientIndex);
|
||||
}
|
||||
|
||||
return Ingredient.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getOutput( final InventoryCrafting craftingInv, final World w )
|
||||
{
|
||||
@@ -406,24 +492,6 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
|
||||
return this.pattern.hashCode();
|
||||
}
|
||||
|
||||
private void warnAboutCraftingManager( boolean foundAlternative )
|
||||
{
|
||||
final String foundAlternativeRecipe = foundAlternative ? "Found alternative recipe." : "NOT FOUND, please report.";
|
||||
|
||||
final StringJoiner joinActualInputs = new StringJoiner( ", " );
|
||||
for( int j = 0; j < this.testFrame.getSizeInventory(); j++ )
|
||||
{
|
||||
final ItemStack stack = this.testFrame.getStackInSlot( j );
|
||||
if( !stack.isEmpty() )
|
||||
{
|
||||
joinActualInputs.add( stack.toString() );
|
||||
}
|
||||
}
|
||||
|
||||
AELog.warn( "Using CraftingManager fallback: Recipe <%s> for output <%s> rejected inputs [%s]. %s",
|
||||
this.standardRecipe.getRegistryName(), this.standardRecipe.getRecipeOutput(), joinActualInputs, foundAlternativeRecipe );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( final Object obj )
|
||||
{
|
||||
|
||||
@@ -187,20 +187,15 @@ public class TickHandler
|
||||
if( ev.type == Type.WORLD && ev.phase == Phase.END )
|
||||
{
|
||||
final WorldTickEvent wte = (WorldTickEvent) ev;
|
||||
synchronized( this.craftingJobs )
|
||||
synchronized ( this.craftingJobs )
|
||||
{
|
||||
final Collection<CraftingJob> jobSet = this.craftingJobs.get( wte.world );
|
||||
if( !jobSet.isEmpty() )
|
||||
{
|
||||
final Iterator<CraftingJob> i = jobSet.iterator();
|
||||
while( i.hasNext() )
|
||||
{
|
||||
final CraftingJob cj = i.next();
|
||||
if( !cj.simulateFor() )
|
||||
{
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
if (!jobSet.isEmpty()) {
|
||||
final int jobSize = jobSet.size();
|
||||
final int microSecondsPerTick = AEConfig.instance().getCraftingCalculationTimePerTick() * 1000;
|
||||
final int simTime = Math.max(1, microSecondsPerTick / jobSize);
|
||||
|
||||
jobSet.removeIf( cj -> !cj.simulateFor( simTime ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
@@ -139,8 +147,12 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
|
||||
}
|
||||
|
||||
// prefer pure crystals.
|
||||
for( ItemStack stack : ingredient.getAllIngredients() )
|
||||
for ( ItemStack stack : ingredient.getAllIngredients() )
|
||||
{
|
||||
if( stack == null )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if( Platform.isRecipePrioritized( stack ) )
|
||||
{
|
||||
list.add( 0, stack );
|
||||
@@ -151,7 +163,7 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
|
||||
}
|
||||
}
|
||||
|
||||
for( final ItemStack is : list )
|
||||
for ( final ItemStack is : list )
|
||||
{
|
||||
final NBTTagCompound tag = new NBTTagCompound();
|
||||
is.writeToNBT( tag );
|
||||
|
||||
@@ -164,6 +164,8 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent,
|
||||
return Upgrades.INVERTER;
|
||||
case CARD_CRAFTING:
|
||||
return Upgrades.CRAFTING;
|
||||
case CARD_PATTERN_EXPANSION:
|
||||
return Upgrades.PATTERN_EXPANSION;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -118,7 +118,10 @@ public enum MaterialType
|
||||
FLUID_CELL1K_PART( 54, "material_fluid_cell1k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
|
||||
FLUID_CELL4K_PART( 55, "material_fluid_cell4k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
|
||||
FLUID_CELL16K_PART( 56, "material_fluid_cell16k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
|
||||
FLUID_CELL64K_PART( 57, "material_fluid_cell64k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) );
|
||||
FLUID_CELL64K_PART( 57, "material_fluid_cell64k_part", EnumSet.of( AEFeature.STORAGE_CELLS ) ),
|
||||
|
||||
CARD_PATTERN_EXPANSION( 58, "material_card_pattern_expansion", EnumSet.of( AEFeature.ADVANCED_CARDS ) );
|
||||
|
||||
|
||||
private final Set<AEFeature> features;
|
||||
private final ModelResourceLocation model;
|
||||
|
||||
@@ -225,7 +225,7 @@ public class ItemEncodedPattern extends AEBaseItem implements ICraftingPatternIt
|
||||
|
||||
final ICraftingPatternDetails details = this.getPatternForItem( item, w );
|
||||
|
||||
out = details != null ? details.getOutputs()[0].createItemStack() : ItemStack.EMPTY;
|
||||
out = details != null ? details.getCondensedOutputs()[0].createItemStack() : ItemStack.EMPTY;
|
||||
|
||||
SIMPLE_CACHE.put( item, out );
|
||||
return out;
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,22 +291,22 @@ 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() )
|
||||
{
|
||||
for( IAEItemStack out : details.getOutputs() )
|
||||
for( IAEItemStack out : details.getCondensedOutputs() )
|
||||
{
|
||||
out = out.copy();
|
||||
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()
|
||||
|
||||
@@ -19,20 +19,10 @@
|
||||
package appeng.me.cache;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.NavigableSet;
|
||||
import java.util.PriorityQueue;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import com.google.common.collect.HashMultiset;
|
||||
import com.google.common.collect.Multiset;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.*;
|
||||
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
@@ -63,7 +53,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 +66,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<>();
|
||||
private final Set<IAEPowerStorage> requesters = new LinkedHashSet<>();
|
||||
private final Multimap<Integer,IAEPowerStorage> providers = HashMultimap.create();
|
||||
// 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 Multimap<Integer,IAEPowerStorage> requesters = HashMultimap.create();
|
||||
// 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,12 +115,16 @@ 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 )
|
||||
{
|
||||
this.myGrid = g;
|
||||
this.requesters.add( this.localStorage );
|
||||
this.providers.add( this.localStorage );
|
||||
this.requesters.put( 0, this.localStorage );
|
||||
this.providers.put( 1, this.localStorage );
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
@@ -143,18 +152,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;
|
||||
}
|
||||
@@ -197,7 +220,7 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
if( this.drainPerTick > 0.0001 )
|
||||
{
|
||||
final double drained = this.extractAEPower( this.getIdlePowerUsage(), Actionable.MODULATE, PowerMultiplier.CONFIG );
|
||||
currentlyHasPower = drained >= this.drainPerTick - 0.001;
|
||||
currentlyHasPower = drained >= this.drainPerTick - 0.001 && this.getStoredPower() > 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -284,7 +307,7 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
{
|
||||
this.availableTicksSinceUpdate = 0;
|
||||
this.globalAvailablePower = 0;
|
||||
for( final IAEPowerStorage p : this.providers )
|
||||
for( final IAEPowerStorage p : this.providers.values() )
|
||||
{
|
||||
this.globalAvailablePower += p.getAECurrentPower();
|
||||
}
|
||||
@@ -301,20 +324,51 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
{
|
||||
double extractedPower = 0;
|
||||
|
||||
final Iterator<IAEPowerStorage> it = this.providers.iterator();
|
||||
|
||||
while( extractedPower < amt && it.hasNext() )
|
||||
{
|
||||
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 )
|
||||
providersToAdd.forEach( provider -> {
|
||||
if( provider instanceof GridPowerStorage )
|
||||
{
|
||||
it.remove();
|
||||
providers.put( 1, provider );
|
||||
}
|
||||
else
|
||||
{
|
||||
providers.put( 0, provider );
|
||||
}
|
||||
} );
|
||||
|
||||
providersToAdd.clear();
|
||||
|
||||
final Iterator<IAEPowerStorage> it = this.providers.values().iterator();
|
||||
|
||||
ongoingExtractOperation = true;
|
||||
try
|
||||
{
|
||||
while ( extractedPower < amt && it.hasNext() )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
} finally
|
||||
{
|
||||
providerToRemove.forEach( provider -> {
|
||||
if( provider instanceof GridPowerStorage )
|
||||
{
|
||||
providers.remove( 1, provider );
|
||||
}
|
||||
else
|
||||
{
|
||||
providers.remove( 0, provider );
|
||||
}
|
||||
} );
|
||||
this.providerToRemove.clear();
|
||||
ongoingExtractOperation = false;
|
||||
}
|
||||
|
||||
final double result = Math.min( extractedPower, amt );
|
||||
@@ -338,17 +392,47 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
{
|
||||
final double originalAmount = amt;
|
||||
|
||||
final Iterator<IAEPowerStorage> it = this.requesters.iterator();
|
||||
|
||||
while( amt > 0 && it.hasNext() )
|
||||
{
|
||||
final IAEPowerStorage node = it.next();
|
||||
amt = node.injectAEPower( amt, mode );
|
||||
|
||||
if( amt > 0 && mode == Actionable.MODULATE )
|
||||
requesterToAdd.forEach( requester -> {
|
||||
if( requester instanceof GridPowerStorage )
|
||||
{
|
||||
it.remove();
|
||||
requesters.put( 0, requester );
|
||||
}
|
||||
else
|
||||
{
|
||||
requesters.put( 1, requester );
|
||||
}
|
||||
} );
|
||||
|
||||
final Iterator<IAEPowerStorage> it = this.requesters.values().iterator();
|
||||
|
||||
ongoingInjectOperation = true;
|
||||
try
|
||||
{
|
||||
while ( amt > 0 && it.hasNext() )
|
||||
{
|
||||
final IAEPowerStorage node = it.next();
|
||||
|
||||
amt = node.injectAEPower( amt, mode );
|
||||
|
||||
if( amt > 0 && mode == Actionable.MODULATE )
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
} finally
|
||||
{
|
||||
requesterToRemove.forEach( requester -> {
|
||||
if( requester instanceof GridPowerStorage )
|
||||
{
|
||||
requesters.remove( 0, requester );
|
||||
}
|
||||
else
|
||||
{
|
||||
requesters.remove( 1, requester );
|
||||
}
|
||||
} );
|
||||
this.requesterToRemove.clear();
|
||||
ongoingInjectOperation = false;
|
||||
}
|
||||
|
||||
final double overflow = Math.max( 0.0, amt );
|
||||
@@ -366,7 +450,7 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
{
|
||||
double required = 0;
|
||||
|
||||
final Iterator<IAEPowerStorage> it = this.requesters.iterator();
|
||||
final Iterator<IAEPowerStorage> it = this.requesters.values().iterator();
|
||||
while( required < maxRequired && it.hasNext() )
|
||||
{
|
||||
final IAEPowerStorage node = it.next();
|
||||
@@ -428,11 +512,7 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
@Override
|
||||
public double getStoredPower()
|
||||
{
|
||||
if( this.availableTicksSinceUpdate > 90 )
|
||||
{
|
||||
this.refreshPower();
|
||||
}
|
||||
|
||||
this.refreshPower();
|
||||
return Math.max( 0.0, this.globalAvailablePower );
|
||||
}
|
||||
|
||||
@@ -505,9 +585,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 +616,58 @@ public class EnergyGridCache implements IEnergyGrid
|
||||
}
|
||||
}
|
||||
|
||||
private void addRequester(IAEPowerStorage requester) {
|
||||
Preconditions.checkState(!ongoingInjectOperation,
|
||||
"Cannot modify energy requesters while energy is being injected.");
|
||||
if( requester instanceof GridPowerStorage )
|
||||
{
|
||||
requesters.put( 0, requester );
|
||||
}
|
||||
else
|
||||
{
|
||||
requesters.put( 1, requester );
|
||||
}
|
||||
}
|
||||
|
||||
private void removeRequester(IAEPowerStorage requester) {
|
||||
Preconditions.checkState(!ongoingInjectOperation,
|
||||
"Cannot modify energy requesters while energy is being injected.");
|
||||
if( requester instanceof GridPowerStorage )
|
||||
{
|
||||
requesters.remove( 0, requester );
|
||||
}
|
||||
else
|
||||
{
|
||||
requesters.remove( 1, requester );
|
||||
}
|
||||
}
|
||||
|
||||
private void addProvider(IAEPowerStorage provider) {
|
||||
Preconditions.checkState(!ongoingExtractOperation,
|
||||
"Cannot modify energy providers while energy is being extracted.");
|
||||
if( provider instanceof GridPowerStorage )
|
||||
{
|
||||
providers.put( 1, provider );
|
||||
}
|
||||
else
|
||||
{
|
||||
providers.put( 0, provider );
|
||||
}
|
||||
}
|
||||
|
||||
private void removeProvider(IAEPowerStorage provider)
|
||||
{
|
||||
Preconditions.checkState( !ongoingExtractOperation, "Cannot modify energy providers while energy is being extracted." );
|
||||
if( provider instanceof GridPowerStorage )
|
||||
{
|
||||
providers.remove( 1, provider );
|
||||
}
|
||||
else
|
||||
{
|
||||
providers.remove( 0, provider );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNode( final IGridNode node, final IGridHost machine )
|
||||
{
|
||||
@@ -554,12 +699,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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,20 +19,10 @@
|
||||
package appeng.me.cache;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Deque;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Queues;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.events.MENetworkStorageEvent;
|
||||
@@ -41,9 +31,19 @@ import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IFluidStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.me.storage.ItemWatcher;
|
||||
import com.google.common.collect.Queues;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Deque;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
||||
public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
@@ -58,19 +58,21 @@ 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;
|
||||
private boolean forceUpdate = false;
|
||||
@Nonnegative
|
||||
private int localDepthSemaphore = 0;
|
||||
private long gridItemCount;
|
||||
private long gridFluidCount;
|
||||
|
||||
public NetworkMonitor( final GridStorageCache cache, final IStorageChannel<T> chan )
|
||||
{
|
||||
this.myGridCache = cache;
|
||||
this.myChannel = chan;
|
||||
this.cachedList = chan.createList();
|
||||
this.listeners = new HashMap<>();
|
||||
this.listeners = new Object2ObjectOpenHashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,21 +90,7 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
@Override
|
||||
public T extractItems( final T request, final Actionable mode, final IActionSource src )
|
||||
{
|
||||
if( mode == Actionable.SIMULATE )
|
||||
{
|
||||
return this.getHandler().extractItems( request, mode, src );
|
||||
}
|
||||
|
||||
this.localDepthSemaphore++;
|
||||
final T leftover = this.getHandler().extractItems( request, mode, src );
|
||||
this.localDepthSemaphore--;
|
||||
|
||||
if( this.localDepthSemaphore == 0 )
|
||||
{
|
||||
this.monitorDifference( request.copy(), leftover, true, src );
|
||||
}
|
||||
|
||||
return leftover;
|
||||
return this.getHandler().extractItems( request, mode, src );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -135,13 +123,39 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
return this.getHandler().getSlot();
|
||||
}
|
||||
|
||||
public long getGridCurrentCount()
|
||||
{
|
||||
if( myChannel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
|
||||
{
|
||||
return gridItemCount;
|
||||
}
|
||||
else if( myChannel == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) )
|
||||
{
|
||||
return gridFluidCount;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long incGridCurrentCount(long count)
|
||||
{
|
||||
if( myChannel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
|
||||
{
|
||||
return gridItemCount += count;
|
||||
}
|
||||
else if( myChannel == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) )
|
||||
{
|
||||
return gridFluidCount += count;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IItemList<T> getStorageList()
|
||||
{
|
||||
if( hasChanged )
|
||||
if( forceUpdate )
|
||||
{
|
||||
hasChanged = false;
|
||||
forceUpdate = false;
|
||||
this.cachedList.resetStatus();
|
||||
return this.getAvailableItems( this.cachedList );
|
||||
}
|
||||
@@ -152,21 +166,7 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
@Override
|
||||
public T injectItems( final T input, final Actionable mode, final IActionSource src )
|
||||
{
|
||||
if( mode == Actionable.SIMULATE )
|
||||
{
|
||||
return this.getHandler().injectItems( input, mode, src );
|
||||
}
|
||||
|
||||
this.localDepthSemaphore++;
|
||||
final T leftover = this.getHandler().injectItems( input, mode, src );
|
||||
this.localDepthSemaphore--;
|
||||
|
||||
if( this.localDepthSemaphore == 0 )
|
||||
{
|
||||
this.monitorDifference( input.copy(), leftover, false, src );
|
||||
}
|
||||
|
||||
return leftover;
|
||||
return this.getHandler().injectItems( input, mode, src );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -198,30 +198,8 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
return this.listeners.entrySet().iterator();
|
||||
}
|
||||
|
||||
private T monitorDifference( final IAEStack<T> original, final T leftOvers, final boolean extraction, final IActionSource src )
|
||||
{
|
||||
final T diff = original.copy();
|
||||
|
||||
if( extraction )
|
||||
{
|
||||
diff.setStackSize( leftOvers == null ? 0 : -leftOvers.getStackSize() );
|
||||
}
|
||||
else if( leftOvers != null )
|
||||
{
|
||||
diff.decStackSize( leftOvers.getStackSize() );
|
||||
}
|
||||
|
||||
if( diff.getStackSize() != 0 )
|
||||
{
|
||||
this.postChangesToListeners( ImmutableList.of( diff ), src );
|
||||
}
|
||||
|
||||
return leftOvers;
|
||||
}
|
||||
|
||||
private void notifyListenersOfChange( final Iterable<T> diff, final IActionSource src )
|
||||
{
|
||||
this.hasChanged = true;
|
||||
final Iterator<Entry<IMEMonitorHandlerReceiver<T>, Object>> i = this.getListeners();
|
||||
|
||||
while( i.hasNext() )
|
||||
@@ -239,54 +217,38 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
}
|
||||
}
|
||||
|
||||
private void postChangesToListeners( final Iterable<T> changes, final IActionSource src )
|
||||
{
|
||||
this.postChange( true, changes, src );
|
||||
}
|
||||
|
||||
protected void postChange( final boolean add, final Iterable<T> changes, final IActionSource src )
|
||||
{
|
||||
if( this.localDepthSemaphore > 0 || GLOBAL_DEPTH.contains( this ) )
|
||||
if ( GLOBAL_DEPTH.contains( this ))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GLOBAL_DEPTH.push( this );
|
||||
this.localDepthSemaphore++;
|
||||
|
||||
this.sendEvent = true;
|
||||
|
||||
this.notifyListenersOfChange( changes, src );
|
||||
|
||||
for( final T changedItem : changes )
|
||||
for ( final T changedItem : changes )
|
||||
{
|
||||
T difference = changedItem;
|
||||
|
||||
if( !add && changedItem != null )
|
||||
{
|
||||
difference = changedItem.copy();
|
||||
difference.setStackSize( -changedItem.getStackSize() );
|
||||
changedItem.setStackSize( -changedItem.getStackSize() );
|
||||
}
|
||||
|
||||
incGridCurrentCount( changedItem.getStackSize() );
|
||||
this.cachedList.add( changedItem );
|
||||
|
||||
if( this.myGridCache.getInterestManager().containsKey( changedItem ) )
|
||||
{
|
||||
final Collection<ItemWatcher> list = this.myGridCache.getInterestManager().get( changedItem );
|
||||
|
||||
if( !list.isEmpty() )
|
||||
{
|
||||
IAEStack<T> fullStack = this.getStorageList().findPrecise( changedItem );
|
||||
|
||||
if( fullStack == null )
|
||||
{
|
||||
fullStack = changedItem.copy();
|
||||
fullStack.setStackSize( 0 );
|
||||
}
|
||||
|
||||
this.myGridCache.getInterestManager().enableTransactions();
|
||||
|
||||
for( final ItemWatcher iw : list )
|
||||
{
|
||||
iw.getHost().onStackChange( this.getStorageList(), fullStack, difference, src, this.getChannel() );
|
||||
iw.getHost().onStackChange( changedItem, this.getChannel() );
|
||||
}
|
||||
|
||||
this.myGridCache.getInterestManager().disableTransactions();
|
||||
@@ -294,8 +256,9 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
}
|
||||
}
|
||||
|
||||
this.notifyListenersOfChange( changes, src );
|
||||
|
||||
final NetworkMonitor<?> last = GLOBAL_DEPTH.pop();
|
||||
this.localDepthSemaphore--;
|
||||
|
||||
if( last != this )
|
||||
{
|
||||
@@ -305,10 +268,10 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
|
||||
void forceUpdate()
|
||||
{
|
||||
this.hasChanged = true;
|
||||
this.forceUpdate = true;
|
||||
|
||||
final Iterator<Entry<IMEMonitorHandlerReceiver<T>, Object>> i = this.getListeners();
|
||||
while( i.hasNext() )
|
||||
while ( i.hasNext() )
|
||||
{
|
||||
final Entry<IMEMonitorHandlerReceiver<T>, Object> o = i.next();
|
||||
final IMEMonitorHandlerReceiver<T> receiver = o.getKey();
|
||||
@@ -331,5 +294,6 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
|
||||
this.sendEvent = false;
|
||||
this.myGridCache.getGrid().postEvent( new MENetworkStorageEvent( this, this.myChannel ) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -138,7 +138,6 @@ public class TickManagerCache implements ITickManager
|
||||
tt.addEntityCrashInfo( crashreportcategory );
|
||||
throw new ReportedException( crashreport );
|
||||
}
|
||||
PartLevelEmitter.wipeCache();
|
||||
}
|
||||
|
||||
private void addToQueue( final TickTracker tt )
|
||||
|
||||
@@ -23,6 +23,9 @@ import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.helpers.DualityInterface;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
@@ -233,8 +236,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;
|
||||
}
|
||||
|
||||
@@ -292,7 +296,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() ) );
|
||||
|
||||
@@ -431,6 +435,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;
|
||||
@@ -485,22 +494,87 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canCraft( final ICraftingPatternDetails details, final IAEItemStack[] condensedInputs )
|
||||
private boolean canCraft(final ICraftingPatternDetails details, final IAEItemStack[] condensedInputs)
|
||||
{
|
||||
for( IAEItemStack g : condensedInputs )
|
||||
if( !details.isCraftable() )
|
||||
{
|
||||
// Processing patterns are relatively easy
|
||||
for ( IAEItemStack input : condensedInputs )
|
||||
{
|
||||
final IAEItemStack ais = this.inventory.extractItems( input.copy(), Actionable.SIMULATE,
|
||||
this.machineSrc );
|
||||
|
||||
if( details.isCraftable() )
|
||||
if( ais == null || ais.getStackSize() < input.getStackSize() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( details.canSubstitute() )
|
||||
{
|
||||
// When substitutions are allowed, we have to keep track of which items we've reserved
|
||||
IAEItemStack[] inputs = details.getInputs();
|
||||
Map<IAEItemStack, Integer> consumedCount = new HashMap<>();
|
||||
for ( int i = 0; i < inputs.length; i++ )
|
||||
{
|
||||
List<IAEItemStack> substitutes = details.getSubstituteInputs( i );
|
||||
if( substitutes.isEmpty() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean found = false;
|
||||
for ( IAEItemStack substitute : substitutes )
|
||||
{
|
||||
for ( IAEItemStack fuzz : this.inventory.getItemList().findFuzzy( substitute, FuzzyMode.IGNORE_ALL ) )
|
||||
{
|
||||
int alreadyConsumed = consumedCount.getOrDefault( fuzz, 0 );
|
||||
if( fuzz.getStackSize() - alreadyConsumed <= 0 )
|
||||
{
|
||||
continue; // Already fully consumed by a previous slot of this recipe
|
||||
}
|
||||
|
||||
fuzz = fuzz.copy();
|
||||
fuzz.setStackSize( 1 ); // We're iterating over non condensed inputs which means there's 1 of each needed
|
||||
final IAEItemStack ais = this.inventory.extractItems( fuzz, Actionable.SIMULATE,
|
||||
this.machineSrc );
|
||||
|
||||
if( ais != null && ais.getStackSize() > 0 )
|
||||
{
|
||||
// Mark 1 of the stack as consumed
|
||||
consumedCount.merge( fuzz, 1, Integer::sum );
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( found )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( !found )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// When no substitutions can occur, we can simply check that all items are accounted since
|
||||
// each type of item should only occur once
|
||||
for ( IAEItemStack g : condensedInputs )
|
||||
{
|
||||
boolean found = false;
|
||||
|
||||
for( IAEItemStack fuzz : this.inventory.getItemList().findFuzzy( g, FuzzyMode.IGNORE_ALL ) )
|
||||
for ( IAEItemStack fuzz : this.inventory.getItemList().findFuzzy( g, FuzzyMode.IGNORE_ALL ) )
|
||||
{
|
||||
fuzz = fuzz.copy();
|
||||
fuzz.setStackSize( g.getStackSize() );
|
||||
final IAEItemStack ais = this.inventory.extractItems( fuzz, Actionable.SIMULATE, this.machineSrc );
|
||||
|
||||
if (ais != null && ais.getStackSize() == g.getStackSize())
|
||||
if( ais != null && ais.getStackSize() >= g.getStackSize() )
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
@@ -517,15 +591,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final IAEItemStack ais = this.inventory.extractItems( g.copy(), Actionable.SIMULATE, this.machineSrc );
|
||||
|
||||
if (ais == null || ais.getStackSize() < g.getStackSize())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -680,71 +746,67 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||
ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||
boolean found = false;
|
||||
|
||||
for( int x = 0; x < input.length; x++ )
|
||||
{
|
||||
if( input[x] != null )
|
||||
{
|
||||
for (int x = 0; x < input.length; x++) {
|
||||
if (input[x] != null) {
|
||||
found = false;
|
||||
|
||||
if( details.isCraftable() )
|
||||
{
|
||||
if (details.isCraftable()) {
|
||||
final Collection<IAEItemStack> itemList;
|
||||
|
||||
if( details.canSubstitute() )
|
||||
{
|
||||
itemList = this.inventory.getItemList().findFuzzy( input[x], FuzzyMode.IGNORE_ALL );
|
||||
}
|
||||
else
|
||||
{
|
||||
itemList = new ArrayList<>( 1 );
|
||||
if (details.canSubstitute()) {
|
||||
final List<IAEItemStack> substitutes = details.getSubstituteInputs(x);
|
||||
itemList = new ArrayList<>(substitutes.size());
|
||||
|
||||
final IAEItemStack item = this.inventory.getItemList().findPrecise( input[x] );
|
||||
for (IAEItemStack stack : substitutes) {
|
||||
itemList.addAll(this.inventory.getItemList().findFuzzy(stack,
|
||||
FuzzyMode.IGNORE_ALL));
|
||||
}
|
||||
} else {
|
||||
itemList = new ArrayList<>(1);
|
||||
|
||||
if( item != null )
|
||||
{
|
||||
itemList.add( item );
|
||||
final IAEItemStack item = this.inventory.getItemList()
|
||||
.findPrecise(input[x]);
|
||||
|
||||
if (item != null) {
|
||||
itemList.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
for( IAEItemStack fuzz : itemList )
|
||||
{
|
||||
for (IAEItemStack fuzz : itemList) {
|
||||
fuzz = fuzz.copy();
|
||||
fuzz.setStackSize( input[x].getStackSize() );
|
||||
fuzz.setStackSize(input[x].getStackSize());
|
||||
|
||||
if( details.isValidItemForSlot( x, fuzz.createItemStack(), this.getWorld() ) )
|
||||
{
|
||||
final IAEItemStack ais = this.inventory.extractItems( fuzz, Actionable.MODULATE, this.machineSrc );
|
||||
final ItemStack is = ais == null ? ItemStack.EMPTY : ais.createItemStack();
|
||||
if (details.isValidItemForSlot(x, fuzz.createItemStack(),
|
||||
this.getWorld())) {
|
||||
final IAEItemStack ais = this.inventory.extractItems(fuzz,
|
||||
Actionable.MODULATE, this.machineSrc);
|
||||
final ItemStack is = ais == null ? ItemStack.EMPTY
|
||||
: ais.createItemStack();
|
||||
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
this.postChange( AEItemStack.fromItemStack( is ), this.machineSrc );
|
||||
ic.setInventorySlotContents( x, is );
|
||||
if (!is.isEmpty()) {
|
||||
this.postChange(AEItemStack.fromItemStack(is), this.machineSrc);
|
||||
ic.setInventorySlotContents(x, is);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final IAEItemStack ais = this.inventory.extractItems( input[x].copy(), Actionable.MODULATE, this.machineSrc );
|
||||
} else {
|
||||
final IAEItemStack ais = this.inventory.extractItems(input[x].copy(),
|
||||
Actionable.MODULATE, this.machineSrc);
|
||||
final ItemStack is = ais == null ? ItemStack.EMPTY : ais.createItemStack();
|
||||
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
this.postChange( input[x], this.machineSrc );
|
||||
ic.setInventorySlotContents( x, is );
|
||||
if( is.getCount() == input[x].getStackSize() )
|
||||
{
|
||||
if (!is.isEmpty()) {
|
||||
this.postChange(input[x], this.machineSrc);
|
||||
ic.setInventorySlotContents(x, is);
|
||||
if (is.getCount() == input[x].getStackSize()) {
|
||||
found = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !found )
|
||||
{
|
||||
if (!found) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -828,6 +890,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 )
|
||||
@@ -838,23 +901,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();
|
||||
}
|
||||
@@ -939,14 +1003,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();
|
||||
@@ -1338,12 +1401,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()
|
||||
|
||||
@@ -23,9 +23,10 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
|
||||
public class GenericInterestManager<T>
|
||||
@@ -101,12 +102,30 @@ public class GenericInterestManager<T>
|
||||
|
||||
public boolean containsKey( final IAEStack stack )
|
||||
{
|
||||
if( stack.isItem() && ( ( AEItemStack ) stack ).getItem().isDamageable() )
|
||||
{
|
||||
return this.container.keySet().stream().filter( s -> s.isItem() )
|
||||
.anyMatch( s -> s.fuzzyComparison( stack, FuzzyMode.IGNORE_ALL ) );
|
||||
}
|
||||
return this.container.containsKey( stack );
|
||||
}
|
||||
|
||||
public Collection<T> get( final IAEStack stack )
|
||||
{
|
||||
return this.container.get( stack );
|
||||
Collection<T> watchers = new ArrayList<>();
|
||||
if( stack.isItem() && ( ( AEItemStack ) stack ).getItem().isDamageable() )
|
||||
{
|
||||
this.container.keySet().stream().filter( s -> s.isItem() )
|
||||
.filter( k -> k.fuzzyComparison( stack, FuzzyMode.IGNORE_ALL ) )
|
||||
.forEach( key ->
|
||||
watchers.addAll( this.container.get( key ) )
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.container.get( stack );
|
||||
}
|
||||
return watchers;
|
||||
}
|
||||
|
||||
private class SavedTransactions
|
||||
|
||||
@@ -151,7 +151,7 @@ public abstract class AbstractCellInventory<T extends IAEStack<T>> implements IC
|
||||
}
|
||||
|
||||
// clean any old crusty stuff...
|
||||
for( ; x < oldStoredItems && x < this.maxItemTypes; x++ )
|
||||
for( ; x >= oldStoredItems && x < this.maxItemTypes; x++ )
|
||||
{
|
||||
this.tagCompound.removeTag( ITEM_SLOT_KEYS[x] );
|
||||
this.tagCompound.removeTag( ITEM_SLOT_COUNT_KEYS[x] );
|
||||
|
||||
@@ -277,6 +277,7 @@ public class BasicCellInventory<T extends IAEStack<T>> extends AbstractCellInven
|
||||
}
|
||||
|
||||
t.setStackSize( stackSize );
|
||||
t.setCraftable( false );
|
||||
|
||||
if( stackSize > 0 )
|
||||
{
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
package appeng.me.storage;
|
||||
|
||||
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.MachineSource;
|
||||
import appeng.tile.storage.TileDrive;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
@@ -36,6 +40,7 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
|
||||
private final ItemStack is;
|
||||
private final ICellHandler handler;
|
||||
private final IChestOrDrive cord;
|
||||
private IActionSource source;
|
||||
|
||||
public DriveWatcher( final ICellInventoryHandler<T> i, final ItemStack is, final ICellHandler han, final IChestOrDrive cod )
|
||||
{
|
||||
@@ -43,6 +48,7 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
|
||||
this.is = is;
|
||||
this.handler = han;
|
||||
this.cord = cod;
|
||||
this.source = new MachineSource( cod );
|
||||
}
|
||||
|
||||
public int getStatus()
|
||||
@@ -66,6 +72,14 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
|
||||
this.cord.blinkCell( this.getSlot() );
|
||||
this.oldStatus = newStatus;
|
||||
}
|
||||
try
|
||||
{
|
||||
( (TileDrive) this.cord ).getProxy().getStorage().postAlterationOfStoredItems( this.getChannel(), ImmutableList.of( input.copy().setStackSize( input.getStackSize() - ( a == null ? 0 : a.getStackSize() ) ) ), this.source );
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return a;
|
||||
@@ -85,6 +99,15 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
|
||||
this.cord.blinkCell( this.getSlot() );
|
||||
this.oldStatus = newStatus;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
( (TileDrive) this.cord ).getProxy().getStorage().postAlterationOfStoredItems( this.getChannel(), ImmutableList.of( request.copy().setStackSize( -a.getStackSize() ) ), this.source );
|
||||
}
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return a;
|
||||
|
||||
@@ -72,7 +72,7 @@ public class MEMonitorPassThrough<T extends IAEStack<T>> extends MEPassThrough<T
|
||||
final IItemList<T> after = this.getInternal() == null ? this.getWrappedChannel().createList() : this.getInternal()
|
||||
.getAvailableItems( new ItemListIgnoreCrafting( this.getWrappedChannel().createList() ) );
|
||||
|
||||
if( this.monitor != null )
|
||||
if( this.monitor != null && this.listeners.size() > 0 )
|
||||
{
|
||||
this.monitor.addListener( this, this.monitor );
|
||||
}
|
||||
@@ -90,6 +90,13 @@ public class MEMonitorPassThrough<T extends IAEStack<T>> extends MEPassThrough<T
|
||||
@Override
|
||||
public void addListener( final IMEMonitorHandlerReceiver<T> l, final Object verificationToken )
|
||||
{
|
||||
if( this.listeners.size() == 0 )
|
||||
{
|
||||
if( this.monitor != null )
|
||||
{
|
||||
this.monitor.addListener( this, this.monitor );
|
||||
}
|
||||
}
|
||||
this.listeners.put( l, verificationToken );
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,8 @@ import appeng.util.item.AEItemStack;
|
||||
|
||||
public class PartExportBus extends PartSharedItemBus implements ICraftingRequester
|
||||
{
|
||||
private final int[] failedCraftTriesSlot = {0,0,0,0,0,0,0,0,0};
|
||||
|
||||
public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/export_bus_base" );
|
||||
|
||||
@PartModels
|
||||
@@ -140,7 +142,7 @@ public class PartExportBus extends PartSharedItemBus implements ICraftingRequest
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
int x;
|
||||
int x = 0;
|
||||
|
||||
for( x = 0; x < this.availableSlots() && this.itemToSend > 0; x++ )
|
||||
{
|
||||
@@ -151,8 +153,16 @@ public class PartExportBus extends PartSharedItemBus implements ICraftingRequest
|
||||
if( ais == null || this.itemToSend <= 0 ) continue;
|
||||
|
||||
if ( this.craftOnly() ) {
|
||||
this.didSomething = this.craftingTracker.handleCrafting(slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(),
|
||||
this.getProxy().getGrid(), cg, this.mySrc) || this.didSomething;
|
||||
if (this.failedCraftTriesSlot[x] <= 0) {
|
||||
|
||||
this.didSomething = this.craftingTracker.handleCrafting(slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(),
|
||||
this.getProxy().getGrid(), cg, this.mySrc) || this.didSomething;
|
||||
|
||||
if (this.didSomething) this.failedCraftTriesSlot[x] = 0;
|
||||
else this.failedCraftTriesSlot[x] += 2;
|
||||
}
|
||||
this.failedCraftTriesSlot[x] -= 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
final long before = this.itemToSend;
|
||||
@@ -175,8 +185,15 @@ public class PartExportBus extends PartSharedItemBus implements ICraftingRequest
|
||||
|
||||
if( this.itemToSend == before && this.isCraftingEnabled() )
|
||||
{
|
||||
this.didSomething = this.craftingTracker.handleCrafting(slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(),
|
||||
if (this.failedCraftTriesSlot[x] <= 0) {
|
||||
|
||||
this.didSomething = this.craftingTracker.handleCrafting(slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(),
|
||||
this.getProxy().getGrid(), cg, this.mySrc) || this.didSomething;
|
||||
|
||||
if (this.didSomething) this.failedCraftTriesSlot[x] = 0;
|
||||
else this.failedCraftTriesSlot[x] += 2;
|
||||
}
|
||||
this.failedCraftTriesSlot[x] -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ public class PartFormationPlane extends PartAbstractFormationPlane<IAEItemStack>
|
||||
@Override
|
||||
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
|
||||
{
|
||||
if( this.getProxy().isActive() && channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
|
||||
if( channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
|
||||
{
|
||||
final List<IMEInventoryHandler> handler = new ArrayList<>( 1 );
|
||||
handler.add( this.myHandler );
|
||||
|
||||
@@ -19,40 +19,9 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import appeng.me.Grid;
|
||||
import appeng.me.GridNode;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import it.unimi.dsi.fastutil.objects.Object2LongMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.config.LevelType;
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.config.YesNo;
|
||||
import appeng.api.networking.crafting.ICraftingGrid;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.networking.crafting.ICraftingProvider;
|
||||
import appeng.api.networking.crafting.ICraftingProviderHelper;
|
||||
import appeng.api.networking.crafting.ICraftingWatcher;
|
||||
import appeng.api.networking.crafting.ICraftingWatcherHost;
|
||||
import appeng.api.config.*;
|
||||
import appeng.api.networking.crafting.*;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.networking.energy.IEnergyWatcher;
|
||||
import appeng.api.networking.energy.IEnergyWatcherHost;
|
||||
@@ -72,7 +41,6 @@ import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.api.util.IConfigManager;
|
||||
@@ -81,10 +49,28 @@ import appeng.core.sync.GuiBridge;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.items.parts.PartModels;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.NetworkMonitor;
|
||||
import appeng.parts.PartModel;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.item.OreHelper;
|
||||
import appeng.util.item.OreReference;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherHost, IStackWatcherHost, ICraftingWatcherHost, IMEMonitorHandlerReceiver<IAEItemStack>, ICraftingProvider
|
||||
@@ -123,9 +109,6 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
|
||||
private double centerX;
|
||||
private double centerY;
|
||||
private double centerZ;
|
||||
static Object2LongMap<Grid> gridItemCount = new Object2LongOpenHashMap<>();
|
||||
static Object2ObjectOpenHashMap<Grid, Object2LongMap<AEItemStack>> fuzzyAEItemStackCount = new Object2ObjectOpenHashMap<>();
|
||||
static Object2ObjectOpenHashMap<Grid, Object2LongMap<AEItemStack>> preciseAEItemStackCount = new Object2ObjectOpenHashMap<>();
|
||||
|
||||
@Reflected
|
||||
public PartLevelEmitter( final ItemStack is )
|
||||
@@ -156,12 +139,6 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerChanged( final MENetworkPowerStatusChange c )
|
||||
{
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
final boolean isOn = this.isLevelEmitterOn();
|
||||
@@ -206,9 +183,23 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
|
||||
return flipState ? this.reportingValue >= this.lastReportedValue + 1 : this.reportingValue < this.lastReportedValue + 1;
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerStatusChange( final MENetworkPowerStatusChange powerEvent )
|
||||
{
|
||||
if (this.getProxy().isActive())
|
||||
{
|
||||
onListUpdate();
|
||||
}
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void channelChanged( final MENetworkChannelsChanged c )
|
||||
{
|
||||
if (this.getProxy().isActive())
|
||||
{
|
||||
onListUpdate();
|
||||
}
|
||||
this.updateState();
|
||||
}
|
||||
|
||||
@@ -296,24 +287,37 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
|
||||
|
||||
try
|
||||
{
|
||||
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 || myStack == null )
|
||||
|
||||
if( myStack == null )
|
||||
{
|
||||
this.getProxy()
|
||||
.getStorage()
|
||||
.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
|
||||
.addListener( this,
|
||||
this.getProxy().getGrid() );
|
||||
this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ).addListener( this, this.getProxy().getGrid() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ).removeListener( this );
|
||||
|
||||
if( this.myWatcher != null )
|
||||
{
|
||||
this.myWatcher.add( myStack );
|
||||
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
Optional<OreReference> ores = OreHelper.INSTANCE.getOre( myStack.getDefinition() );
|
||||
if( ores.isPresent() )
|
||||
{
|
||||
for( IAEItemStack iaeItemStack : ores.get().getAEEquivalents() )
|
||||
{
|
||||
this.myWatcher.add( iaeItemStack );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.myWatcher.add( myStack );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.myWatcher.add( myStack );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.updateReportingValue( this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
@@ -323,90 +327,29 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
|
||||
}
|
||||
|
||||
private void updateReportingValue( final IMEMonitor<IAEItemStack> monitor )
|
||||
{
|
||||
updateReportingValue( monitor,null );
|
||||
}
|
||||
|
||||
private void updateReportingValue( final IMEMonitor<IAEItemStack> monitor, Iterable<IAEItemStack> change )
|
||||
{
|
||||
final IAEItemStack myStack = this.config.getAEStackInSlot( 0 );
|
||||
|
||||
GridNode node = (GridNode) (this.getGridNode());
|
||||
|
||||
if( node != null )
|
||||
if( myStack == null )
|
||||
{
|
||||
|
||||
final Grid g = node.getInternalGrid();
|
||||
|
||||
if( myStack == null )
|
||||
if( monitor instanceof NetworkMonitor )
|
||||
{
|
||||
if( change != null )
|
||||
{
|
||||
if( gridItemCount.containsKey( g ) )
|
||||
{
|
||||
change.forEach( iaeItemStack -> lastReportedValue += iaeItemStack.getStackSize() );
|
||||
}
|
||||
}
|
||||
gridItemCount.computeIfAbsent( g, ( aLong ) -> {
|
||||
this.lastReportedValue = 0;
|
||||
monitor.getStorageList().forEach( iaeItemStack -> lastReportedValue += iaeItemStack.getStackSize() );
|
||||
return ( lastReportedValue );
|
||||
} );
|
||||
this.lastReportedValue = gridItemCount.get( g );
|
||||
this.lastReportedValue = ( (NetworkMonitor<IAEItemStack>) monitor ).getGridCurrentCount();
|
||||
}
|
||||
}
|
||||
|
||||
else if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE );
|
||||
if( change != null )
|
||||
{
|
||||
if( fuzzyAEItemStackCount.containsKey( g ) )
|
||||
{
|
||||
change.forEach( iaeItemStack -> {
|
||||
if( iaeItemStack.sameOre( myStack ) ) lastReportedValue += iaeItemStack.getStackSize();
|
||||
} );
|
||||
}
|
||||
}
|
||||
else if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE );
|
||||
|
||||
fuzzyAEItemStackCount.computeIfAbsent( g, ( grid -> new Object2LongOpenHashMap<>() ) );
|
||||
fuzzyAEItemStackCount.get( g ).computeIfAbsent( (AEItemStack) myStack, ( aLong -> {
|
||||
this.lastReportedValue = 0;
|
||||
monitor.getStorageList().findFuzzy( myStack, fzMode ).forEach( iaeItemStack -> lastReportedValue += iaeItemStack.getStackSize() );
|
||||
return ( lastReportedValue );
|
||||
} ) );
|
||||
|
||||
this.lastReportedValue = fuzzyAEItemStackCount.get( g ).get( myStack );
|
||||
if( this.lastReportedValue == 0 )
|
||||
{
|
||||
fuzzyAEItemStackCount.get( g ).remove( myStack );
|
||||
fuzzyAEItemStackCount.trim();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( change != null )
|
||||
{
|
||||
if( preciseAEItemStackCount.containsKey( g ) )
|
||||
{
|
||||
change.forEach( iaeItemStack -> {
|
||||
if( iaeItemStack.isSameType( myStack ) ) lastReportedValue += iaeItemStack.getStackSize();
|
||||
} );
|
||||
}
|
||||
}
|
||||
preciseAEItemStackCount.computeIfAbsent( g, ( grid -> new Object2LongOpenHashMap<>() ) );
|
||||
preciseAEItemStackCount.get( g ).computeIfAbsent( (AEItemStack) myStack, ( aLong -> {
|
||||
this.lastReportedValue = 0;
|
||||
IAEItemStack precise = monitor.getStorageList().findPrecise( myStack );
|
||||
if( precise != null ) lastReportedValue = precise.getStackSize();
|
||||
return ( lastReportedValue );
|
||||
} ) );
|
||||
this.lastReportedValue = preciseAEItemStackCount.get( g ).get( myStack );
|
||||
if( this.lastReportedValue == 0 )
|
||||
{
|
||||
preciseAEItemStackCount.get( g ).remove( myStack );
|
||||
preciseAEItemStackCount.trim();
|
||||
}
|
||||
}
|
||||
this.lastReportedValue = 0;
|
||||
monitor.getStorageList().findFuzzy( myStack, fzMode ).forEach( iaeItemStack -> lastReportedValue += iaeItemStack.getStackSize() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.lastReportedValue = 0;
|
||||
IAEItemStack precise = monitor.getStorageList().findPrecise( myStack );
|
||||
if( precise != null ) lastReportedValue = precise.getStackSize();
|
||||
}
|
||||
this.updateState();
|
||||
}
|
||||
@@ -419,12 +362,23 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStackChange( final IItemList o, final IAEStack fullStack, final IAEStack diffStack, final IActionSource src, final IStorageChannel chan )
|
||||
public void onStackChange( final IAEStack diffStack, final IStorageChannel chan )
|
||||
{
|
||||
if( chan == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) && fullStack.equals( this.config.getAEStackInSlot( 0 ) ) && this
|
||||
.getInstalledUpgrades( Upgrades.FUZZY ) == 0 )
|
||||
if( chan == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
|
||||
{
|
||||
this.lastReportedValue = fullStack.getStackSize();
|
||||
IAEItemStack myStack = this.config.getAEStackInSlot( 0 );
|
||||
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||
{
|
||||
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE );
|
||||
if( Platform.itemComparisons().isFuzzyEqualItem( myStack.getDefinition(), ( (IAEItemStack) diffStack ).getDefinition(), fzMode ) )
|
||||
{
|
||||
this.lastReportedValue += diffStack.getStackSize();
|
||||
}
|
||||
}
|
||||
else if( diffStack.equals( myStack ) )
|
||||
{
|
||||
this.lastReportedValue += diffStack.getStackSize();
|
||||
}
|
||||
this.updateState();
|
||||
}
|
||||
}
|
||||
@@ -459,7 +413,7 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
|
||||
@Override
|
||||
public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource actionSource )
|
||||
{
|
||||
this.updateReportingValue( (IMEMonitor<IAEItemStack>) monitor, change );
|
||||
this.updateReportingValue( (IMEMonitor<IAEItemStack>) monitor );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -636,9 +590,4 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
|
||||
}
|
||||
}
|
||||
|
||||
public static void wipeCache(){
|
||||
fuzzyAEItemStackCount.clear();
|
||||
preciseAEItemStackCount.clear();
|
||||
gridItemCount.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,20 @@
|
||||
package appeng.parts.automation;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.container.slot.SlotRestrictedInput;
|
||||
import appeng.core.Api;
|
||||
import appeng.helpers.DualityInterface;
|
||||
import appeng.util.inv.ItemHandlerIterator;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.config.Upgrades;
|
||||
@@ -33,6 +43,9 @@ import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public abstract class UpgradeInventory extends AppEngInternalInventory implements IAEAppEngInventory
|
||||
{
|
||||
@@ -45,6 +58,7 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
|
||||
private int capacityUpgrades = 0;
|
||||
private int inverterUpgrades = 0;
|
||||
private int craftingUpgrades = 0;
|
||||
private int patternExpansionUpgrades = 0;
|
||||
|
||||
public UpgradeInventory( final IAEAppEngInventory parent, final int s )
|
||||
{
|
||||
@@ -81,6 +95,8 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
|
||||
return this.inverterUpgrades;
|
||||
case CRAFTING:
|
||||
return this.craftingUpgrades;
|
||||
case PATTERN_EXPANSION:
|
||||
return this.patternExpansionUpgrades;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@@ -91,7 +107,7 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
|
||||
private void updateUpgradeInfo()
|
||||
{
|
||||
this.cached = true;
|
||||
this.inverterUpgrades = this.capacityUpgrades = this.redstoneUpgrades = this.speedUpgrades = this.fuzzyUpgrades = this.craftingUpgrades = 0;
|
||||
this.patternExpansionUpgrades = this.inverterUpgrades = this.capacityUpgrades = this.redstoneUpgrades = this.speedUpgrades = this.fuzzyUpgrades = this.craftingUpgrades = 0;
|
||||
|
||||
for( final ItemStack is : this )
|
||||
{
|
||||
@@ -121,6 +137,9 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
|
||||
case CRAFTING:
|
||||
this.craftingUpgrades++;
|
||||
break;
|
||||
case PATTERN_EXPANSION:
|
||||
this.patternExpansionUpgrades++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -132,6 +151,7 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
|
||||
this.speedUpgrades = Math.min( this.speedUpgrades, this.getMaxInstalled( Upgrades.SPEED ) );
|
||||
this.inverterUpgrades = Math.min( this.inverterUpgrades, this.getMaxInstalled( Upgrades.INVERTER ) );
|
||||
this.craftingUpgrades = Math.min( this.craftingUpgrades, this.getMaxInstalled( Upgrades.CRAFTING ) );
|
||||
this.patternExpansionUpgrades = Math.min( this.patternExpansionUpgrades, this.getMaxInstalled( Upgrades.PATTERN_EXPANSION ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -160,6 +180,13 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ItemStack extractItem( int slot, int amount, boolean simulate )
|
||||
{
|
||||
return super.extractItem( slot, amount, simulate );
|
||||
}
|
||||
|
||||
private class UpgradeInvFilter implements IAEItemFilter
|
||||
{
|
||||
|
||||
|
||||
@@ -19,15 +19,11 @@
|
||||
package appeng.parts.misc;
|
||||
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.StorageFilter;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
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;
|
||||
@@ -37,11 +33,19 @@ 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.Platform;
|
||||
import appeng.util.inv.ItemHandlerIterator;
|
||||
import appeng.util.inv.ItemSlot;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import com.google.common.primitives.Ints;
|
||||
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 java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
@@ -49,13 +53,15 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
*/
|
||||
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;
|
||||
private final InventoryCache cache;
|
||||
private StorageFilter mode;
|
||||
|
||||
private ItemStack stackCache = null;
|
||||
|
||||
ItemHandlerAdapter( IItemHandler itemHandler, IGridProxyable proxy )
|
||||
{
|
||||
this.itemHandler = itemHandler;
|
||||
@@ -71,24 +77,36 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
@Override
|
||||
public IAEItemStack injectItems( IAEItemStack iox, Actionable type, IActionSource src )
|
||||
{
|
||||
ItemStack orgInput = iox.createItemStack();
|
||||
// Try to reuse the cached stack
|
||||
@Nullable ItemStack currentCached = stackCache;
|
||||
stackCache = null;
|
||||
|
||||
ItemStack orgInput;
|
||||
int slotCount = this.itemHandler.getSlots();
|
||||
|
||||
if( currentCached != null && iox.isSameType( currentCached ) )
|
||||
{
|
||||
// Cache is suitable, just update the count
|
||||
orgInput = currentCached;
|
||||
currentCached.setCount( Ints.saturatedCast( iox.getStackSize() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
// We need a new stack :-(
|
||||
orgInput = iox.createItemStack();
|
||||
}
|
||||
|
||||
ItemStack remaining = orgInput;
|
||||
|
||||
int slotCount = this.itemHandler.getSlots();
|
||||
boolean simulate = ( type == Actionable.SIMULATE );
|
||||
List<Pair<Integer,Integer>> injectedList = new ArrayList<>();
|
||||
// This uses a brute force approach and tries to jam it in every slot the inventory exposes.
|
||||
for( int i = 0; i < slotCount && !remaining.isEmpty(); i++ )
|
||||
for ( int i = 0; i < slotCount && !remaining.isEmpty(); i++ )
|
||||
{
|
||||
int countPre = remaining.getCount();
|
||||
remaining = this.itemHandler.insertItem( i, remaining, simulate );
|
||||
int countPos = remaining.getCount();
|
||||
if (remaining.isEmpty()){
|
||||
injectedList.add( Pair.of( i,countPre ) );
|
||||
}
|
||||
else if (countPos > countPre) {
|
||||
injectedList.add( Pair.of( i,countPos - countPre ) );
|
||||
}
|
||||
remaining = this.itemHandler.insertItem( i, remaining, type == Actionable.SIMULATE );
|
||||
}
|
||||
|
||||
// Store the stack in the cache for next time.
|
||||
if( !remaining.isEmpty() && remaining != orgInput )
|
||||
{
|
||||
stackCache = remaining;
|
||||
}
|
||||
|
||||
// At this point, we still have some items left...
|
||||
@@ -100,18 +118,15 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
|
||||
if( type == Actionable.MODULATE )
|
||||
{
|
||||
if (this.cache.cachedAeStacks.length == 0) this.cache.update();
|
||||
for ( Pair<Integer, Integer> pair : injectedList )
|
||||
try
|
||||
{
|
||||
if( this.cache.cachedAeStacks[pair.getKey()] == null )
|
||||
{
|
||||
this.cache.cachedAeStacks[pair.getKey()] = iox.copy().setStackSize( pair.getValue() );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.cache.cachedAeStacks[pair.getKey()].incStackSize( pair.getValue() );
|
||||
}
|
||||
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
|
||||
}
|
||||
catch( GridAccessException ex )
|
||||
{
|
||||
// meh
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return AEItemStack.fromItemStack( remaining );
|
||||
@@ -120,22 +135,17 @@ 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();
|
||||
int remainingSize = Ints.saturatedCast( request.getStackSize() );
|
||||
|
||||
// Use this to gather the requested items
|
||||
ItemStack gathered = ItemStack.EMPTY;
|
||||
|
||||
final boolean simulate = ( mode == Actionable.SIMULATE );
|
||||
List<Pair<Integer, Integer>> extractedList = new ArrayList<>();
|
||||
|
||||
|
||||
for ( int i = 0; i < this.itemHandler.getSlots(); i++ )
|
||||
{
|
||||
ItemStack stackInInventorySlot = this.itemHandler.getStackInSlot( i );
|
||||
|
||||
if( !Platform.itemComparisons().isSameItem( stackInInventorySlot, requestedItemStack ) )
|
||||
if( !request.isSameType( stackInInventorySlot ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -161,8 +171,6 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
extracted.setCount( remainingCurrentSlot );
|
||||
}
|
||||
|
||||
extractedList.add( Pair.of( i, extracted.getCount() ) );
|
||||
|
||||
// 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.
|
||||
@@ -176,8 +184,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
}
|
||||
remainingCurrentSlot -= extracted.getCount();
|
||||
}
|
||||
}
|
||||
while ( !extracted.isEmpty() && remainingCurrentSlot > 0 );
|
||||
} while ( !extracted.isEmpty() && remainingCurrentSlot > 0 );
|
||||
|
||||
remainingSize -= stackSizeCurrentSlot - remainingCurrentSlot;
|
||||
|
||||
@@ -190,20 +197,20 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
|
||||
if( !gathered.isEmpty() )
|
||||
{
|
||||
IAEItemStack gatheredAEItemStack = AEItemStack.fromItemStack( gathered );
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
if (this.cache.cachedAeStacks.length == 0) this.cache.update();
|
||||
for ( Pair<Integer, Integer> pair : extractedList )
|
||||
try
|
||||
{
|
||||
this.cache.cachedAeStacks[pair.getKey()].decStackSize( pair.getValue() );
|
||||
if( this.cache.cachedAeStacks[pair.getKey()].getStackSize() == 0 )
|
||||
{
|
||||
this.cache.cachedAeStacks[pair.getKey()] = null;
|
||||
}
|
||||
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
|
||||
}
|
||||
catch( GridAccessException ex )
|
||||
{
|
||||
// meh
|
||||
}
|
||||
}
|
||||
|
||||
return AEItemStack.fromItemStack( gathered );
|
||||
return gatheredAEItemStack;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -257,7 +264,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,11 +279,11 @@ 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 final IItemHandler itemHandler;
|
||||
private final StorageFilter mode;
|
||||
IItemList<IAEItemStack> currentlyCached = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
|
||||
public InventoryCache( IItemHandler itemHandler, StorageFilter mode )
|
||||
{
|
||||
@@ -286,106 +293,58 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
||||
|
||||
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
|
||||
{
|
||||
Arrays.stream( this.cachedAeStacks ).forEach( out::add );
|
||||
currentlyCached.iterator().forEachRemaining( 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 )
|
||||
{
|
||||
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, slots );
|
||||
}
|
||||
IItemList<IAEItemStack> currentlyOnStorage = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
|
||||
for( int slot = 0; slot < slots; slot++ )
|
||||
for ( final ItemSlot is : this )
|
||||
{
|
||||
// Save the old stuff
|
||||
final IAEItemStack oldAeIS = this.cachedAeStacks[slot];
|
||||
ItemStack newIS = this.itemHandler.getStackInSlot( slot );
|
||||
if( this.mode == StorageFilter.EXTRACTABLE_ONLY && !newIS.isEmpty() )
|
||||
final ItemStack newIS = !is.isExtractable() && this.getMode() == StorageFilter.EXTRACTABLE_ONLY ? ItemStack.EMPTY : is.getItemStack();
|
||||
if( !newIS.isEmpty() )
|
||||
{
|
||||
if( this.itemHandler.extractItem( slot, 1, true ).isEmpty() )
|
||||
{
|
||||
newIS = ItemStack.EMPTY;
|
||||
}
|
||||
currentlyOnStorage.add( is.getAEItemStack() );
|
||||
}
|
||||
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 ( final IAEItemStack is : currentlyCached )
|
||||
{
|
||||
for( int slot = slots; slot < this.cachedAeStacks.length; slot++ )
|
||||
{
|
||||
final IAEItemStack aeStack = this.cachedAeStacks[slot];
|
||||
|
||||
if( aeStack != null )
|
||||
{
|
||||
final IAEItemStack a = aeStack.copy();
|
||||
a.setStackSize( -a.getStackSize() );
|
||||
changes.add( a );
|
||||
}
|
||||
}
|
||||
|
||||
// Reduce the cache size
|
||||
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, slots );
|
||||
is.setStackSize( -is.getStackSize() );
|
||||
}
|
||||
|
||||
for ( final IAEItemStack is : currentlyOnStorage )
|
||||
{
|
||||
currentlyCached.add( is );
|
||||
}
|
||||
|
||||
for ( final IAEItemStack is : currentlyCached )
|
||||
{
|
||||
if( is.getStackSize() != 0 )
|
||||
{
|
||||
changes.add( is );
|
||||
}
|
||||
}
|
||||
|
||||
currentlyCached = currentlyOnStorage;
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
private void handlePossibleSlotChanges( int slot, IAEItemStack oldAeIS, ItemStack newIS, List<IAEItemStack> changes )
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
if( oldAeIS != null && oldAeIS.isSameType( newIS ) )
|
||||
{
|
||||
this.handleStackSizeChanged( slot, oldAeIS, newIS, changes );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.handleItemChanged( slot, oldAeIS, newIS, changes );
|
||||
}
|
||||
return new ItemHandlerIterator( this.itemHandler );
|
||||
}
|
||||
|
||||
private void handleStackSizeChanged( int slot, IAEItemStack oldAeIS, ItemStack newIS, List<IAEItemStack> changes )
|
||||
{
|
||||
// Still the same item, but amount might have changed
|
||||
final long diff = newIS.getCount() - oldAeIS.getStackSize();
|
||||
|
||||
if( diff != 0 )
|
||||
{
|
||||
final IAEItemStack stack = oldAeIS.copy();
|
||||
stack.setStackSize( newIS.getCount() );
|
||||
|
||||
this.cachedAeStacks[slot] = stack;
|
||||
|
||||
final IAEItemStack a = stack.copy();
|
||||
a.setStackSize( diff );
|
||||
changes.add( a );
|
||||
}
|
||||
}
|
||||
|
||||
private void handleItemChanged( int slot, IAEItemStack oldAeIS, ItemStack newIS, List<IAEItemStack> changes )
|
||||
{
|
||||
// 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] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +1,6 @@
|
||||
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.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 javax.annotation.Nullable;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
@@ -21,15 +8,23 @@ 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.google.common.primitives.Ints;
|
||||
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 java.util.*;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/**
|
||||
* Wraps an Item Repository in such a way that it can be used as an IMEInventory for items.
|
||||
@@ -38,12 +33,13 @@ 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;
|
||||
private final InventoryCache cache;
|
||||
|
||||
private ItemStack stackCache;
|
||||
|
||||
ItemRepositoryAdapter( IItemRepository itemRepository, IGridProxyable proxy )
|
||||
{
|
||||
@@ -55,12 +51,29 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
||||
@Override
|
||||
public IAEItemStack injectItems( IAEItemStack iox, Actionable type, IActionSource src )
|
||||
{
|
||||
ItemStack orgInput = iox.createItemStack();
|
||||
ItemStack remaining = orgInput;
|
||||
// Try to reuse the cached stack
|
||||
@Nullable ItemStack currentCached = stackCache;
|
||||
stackCache = null;
|
||||
|
||||
boolean simulate = ( type == Actionable.SIMULATE );
|
||||
ItemStack orgInput;
|
||||
if( currentCached != null && iox.isSameType( currentCached ) )
|
||||
{
|
||||
// Cache is suitable, just update the count
|
||||
orgInput = currentCached;
|
||||
currentCached.setCount( Ints.saturatedCast( iox.getStackSize() ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
// We need a new stack :-(
|
||||
orgInput = iox.createItemStack();
|
||||
}
|
||||
ItemStack remaining = this.itemRepository.insertItem( orgInput, type == Actionable.SIMULATE );
|
||||
|
||||
remaining = this.itemRepository.insertItem( remaining, simulate );
|
||||
// Store the stack in the cache for next time.
|
||||
if (!remaining.isEmpty() && remaining != orgInput)
|
||||
{
|
||||
stackCache = remaining;
|
||||
}
|
||||
|
||||
// At this point, we still have some items left...
|
||||
if( remaining == orgInput )
|
||||
@@ -71,24 +84,13 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
||||
|
||||
if( type == Actionable.MODULATE )
|
||||
{
|
||||
if (this.cache.cachedAeStacks.length == 0) this.cache.update();
|
||||
boolean found = false;
|
||||
for (IAEItemStack iaeItemStack : this.cache.cachedAeStacks)
|
||||
try
|
||||
{
|
||||
if( iaeItemStack == null )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if( iaeItemStack.equals( iox ) )
|
||||
{
|
||||
found = true;
|
||||
iaeItemStack.incStackSize( iox.getStackSize() );
|
||||
}
|
||||
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
|
||||
}
|
||||
if (!found)
|
||||
catch( GridAccessException ex )
|
||||
{
|
||||
this.cache.cachedAeStacks = Arrays.copyOf( this.cache.cachedAeStacks, this.cache.cachedAeStacks.length + 1 );
|
||||
this.cache.cachedAeStacks[this.cache.cachedAeStacks.length - 1] = iox.copy();
|
||||
// meh
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,13 +101,11 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
||||
@Override
|
||||
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, IActionSource src )
|
||||
{
|
||||
ItemStack requestedItemStack = request.createItemStack();
|
||||
int remainingSize = requestedItemStack.getCount();
|
||||
int remainingSize = Ints.saturatedCast( request.getStackSize() );
|
||||
|
||||
final boolean simulate = ( mode == Actionable.SIMULATE );
|
||||
|
||||
ItemStack extracted;
|
||||
extracted = this.itemRepository.extractItem( requestedItemStack, remainingSize, simulate );
|
||||
ItemStack extracted = this.itemRepository.extractItem( request.getDefinition(), remainingSize, simulate );
|
||||
|
||||
if( extracted.getCount() > remainingSize )
|
||||
{
|
||||
@@ -118,33 +118,20 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
||||
|
||||
if( !extracted.isEmpty() )
|
||||
{
|
||||
if (this.cache.cachedAeStacks.length == 0) this.cache.update();
|
||||
IAEItemStack iaeExtracted = AEItemStack.fromItemStack( extracted );
|
||||
|
||||
IAEItemStack extractedAEItemStack = AEItemStack.fromItemStack( extracted );
|
||||
if( mode == Actionable.MODULATE )
|
||||
{
|
||||
for ( int i = 0; i < this.cache.cachedAeStacks.length; i++ )
|
||||
try
|
||||
{
|
||||
IAEItemStack iaeItemStack = this.cache.cachedAeStacks[i];
|
||||
if( iaeExtracted.equals( iaeItemStack ) )
|
||||
{
|
||||
if( iaeExtracted.getStackSize() >= iaeItemStack.getStackSize() )
|
||||
{
|
||||
iaeExtracted.decStackSize( iaeItemStack.getStackSize() );
|
||||
this.cache.cachedAeStacks[i] = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
iaeItemStack.decStackSize( iaeExtracted.getStackSize() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
|
||||
}
|
||||
catch( GridAccessException ex )
|
||||
{
|
||||
// meh
|
||||
}
|
||||
}
|
||||
|
||||
return AEItemStack.fromItemStack( extracted );
|
||||
return extractedAEItemStack;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -175,7 +162,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();
|
||||
@@ -215,7 +202,7 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
||||
|
||||
private static class InventoryCache
|
||||
{
|
||||
private IAEItemStack[] cachedAeStacks = new IAEItemStack[0];
|
||||
private IItemList<IAEItemStack> currentlyCached = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
private final IItemRepository iItemRepository;
|
||||
|
||||
public InventoryCache( IItemRepository iItemRepository )
|
||||
@@ -225,7 +212,7 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
||||
|
||||
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
|
||||
{
|
||||
Arrays.stream( this.cachedAeStacks ).forEach( out::add );
|
||||
currentlyCached.iterator().forEachRemaining( out::add );
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -233,94 +220,31 @@ 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> currentlyOnStorage = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
this.iItemRepository.getAllItems().stream().map( s -> AEItemStack.fromItemStack( s.itemPrototype ).setStackSize( s.count ) ).forEach( currentlyOnStorage::add );
|
||||
|
||||
final int size = out.size();
|
||||
|
||||
// Make room for new slots
|
||||
if( size > this.cachedAeStacks.length )
|
||||
for ( final IAEItemStack is : currentlyCached )
|
||||
{
|
||||
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, size );
|
||||
is.setStackSize( -is.getStackSize() );
|
||||
}
|
||||
|
||||
for( int x = 0; x < size; x++ )
|
||||
for ( final IAEItemStack is : currentlyOnStorage )
|
||||
{
|
||||
// Save the old stuff
|
||||
final IAEItemStack oldAeIS = this.cachedAeStacks[x];
|
||||
final IAEItemStack newIS = out.get( x );
|
||||
|
||||
this.handlePossibleSlotChanges( x, oldAeIS, newIS, changes );
|
||||
currentlyCached.add( is );
|
||||
}
|
||||
|
||||
// Handle cases where the number of slots actually is lower now than before
|
||||
if( size < this.cachedAeStacks.length )
|
||||
for ( final IAEItemStack is : currentlyCached )
|
||||
{
|
||||
for( int x = 0; x < this.cachedAeStacks.length; x++ )
|
||||
if( is.getStackSize() != 0 )
|
||||
{
|
||||
final IAEItemStack aeStack = this.cachedAeStacks[x];
|
||||
|
||||
if( aeStack != null )
|
||||
{
|
||||
final IAEItemStack a = aeStack.copy();
|
||||
a.setStackSize( -a.getStackSize() );
|
||||
changes.add( a );
|
||||
}
|
||||
changes.add( is );
|
||||
}
|
||||
|
||||
// Reduce the cache size
|
||||
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, size );
|
||||
}
|
||||
|
||||
currentlyCached = currentlyOnStorage;
|
||||
|
||||
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 )
|
||||
{
|
||||
// Still the same item, but amount might have changed
|
||||
final long diff = newIS.getStackSize() - oldAeIS.getStackSize();
|
||||
|
||||
if( diff != 0 )
|
||||
{
|
||||
final IAEItemStack stack = oldAeIS.copy();
|
||||
stack.setStackSize( newIS.getStackSize() );
|
||||
|
||||
this.cachedAeStacks[slot] = stack;
|
||||
|
||||
final IAEItemStack a = stack.copy();
|
||||
a.setStackSize( diff );
|
||||
changes.add( a );
|
||||
}
|
||||
}
|
||||
|
||||
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] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,13 +262,9 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
{
|
||||
if( this.getProxy().isActive() )
|
||||
{
|
||||
this.getProxy()
|
||||
.getStorage()
|
||||
.postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), change,
|
||||
this.mySrc );
|
||||
this.getProxy().getStorage().postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), change, this.mySrc );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
} catch ( final GridAccessException e )
|
||||
{
|
||||
// :(
|
||||
}
|
||||
@@ -598,7 +594,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
|
||||
{
|
||||
if( channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
|
||||
{
|
||||
final IMEInventoryHandler<IAEItemStack> out = this.getProxy().isActive() ? this.getInternalHandler() : null;
|
||||
final IMEInventoryHandler<IAEItemStack> out = this.getInternalHandler();
|
||||
if( out != null )
|
||||
{
|
||||
return Collections.singletonList( out );
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -21,10 +21,12 @@ package appeng.parts.reporting;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.storage.channels.IFluidStorageChannel;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.util.item.AEStack;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
@@ -43,7 +45,6 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.implementations.parts.IPartStorageMonitor;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.networking.storage.IStackWatcher;
|
||||
import appeng.api.networking.storage.IStackWatcherHost;
|
||||
import appeng.api.parts.IPartModel;
|
||||
@@ -52,7 +53,6 @@ import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.client.render.TesrRenderHelper;
|
||||
import appeng.core.localization.PlayerMessages;
|
||||
import appeng.helpers.Reflected;
|
||||
@@ -385,19 +385,87 @@ public abstract class AbstractPartMonitor extends AbstractPartDisplay implements
|
||||
this.configureWatchers();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerStatusChange( final MENetworkPowerStatusChange ev )
|
||||
{
|
||||
if( !this.getProxy().isPowered() )
|
||||
{
|
||||
if( this.myWatcher != null )
|
||||
{
|
||||
if( this.configuredItem != null )
|
||||
{
|
||||
this.configuredItem.setStackSize( 0 );
|
||||
}
|
||||
if( this.configuredFluid != null )
|
||||
{
|
||||
this.configuredFluid.setStackSize( 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if( this.configuredItem != null )
|
||||
{
|
||||
this.updateReportingValue( this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) );
|
||||
}
|
||||
if( this.configuredFluid != null )
|
||||
{
|
||||
this.updateReportingValue( this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) ) );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// ;P
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void channelChanged( final MENetworkChannelsChanged c )
|
||||
{
|
||||
if( !this.getProxy().isPowered() )
|
||||
{
|
||||
if( this.myWatcher != null )
|
||||
{
|
||||
if( this.configuredItem != null )
|
||||
{
|
||||
this.configuredItem.setStackSize( 0 );
|
||||
}
|
||||
if( this.configuredFluid != null )
|
||||
{
|
||||
this.configuredFluid.setStackSize( 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if( this.configuredItem != null )
|
||||
{
|
||||
this.updateReportingValue( this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ) );
|
||||
}
|
||||
if( this.configuredFluid != null )
|
||||
{
|
||||
this.updateReportingValue( this.getProxy().getStorage().getInventory( AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) ) );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// ;P
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStackChange( final IItemList o, final IAEStack fullStack, final IAEStack diffStack, final IActionSource src, final IStorageChannel chan )
|
||||
public void onStackChange( final IAEStack diffStack, final IStorageChannel chan )
|
||||
{
|
||||
if( this.configuredItem != null )
|
||||
{
|
||||
if( fullStack == null )
|
||||
{
|
||||
this.configuredItem.setStackSize( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.configuredItem.setStackSize( fullStack.getStackSize() );
|
||||
}
|
||||
long diff = this.configuredItem.getStackSize() + diffStack.getStackSize();
|
||||
this.configuredItem.setStackSize( diff >= 0 ? this.configuredItem.getStackSize() + diffStack.getStackSize() : 0 );
|
||||
|
||||
final long stackSize = this.configuredItem.getStackSize();
|
||||
final String humanReadableText = NUMBER_CONVERTER.toWideReadableForm( stackSize );
|
||||
@@ -410,14 +478,8 @@ public abstract class AbstractPartMonitor extends AbstractPartDisplay implements
|
||||
}
|
||||
else if( this.configuredFluid != null )
|
||||
{
|
||||
if( fullStack == null )
|
||||
{
|
||||
this.configuredFluid.setStackSize( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.configuredFluid.setStackSize( fullStack.getStackSize() );
|
||||
}
|
||||
long diff = this.configuredFluid.getStackSize() + diffStack.getStackSize();
|
||||
this.configuredFluid.setStackSize( diff >= 0 ? this.configuredFluid.getStackSize() + diffStack.getStackSize() : 0 );
|
||||
|
||||
final long stackSize = this.configuredFluid.getStackSize() / 1000;
|
||||
final String humanReadableText = NUMBER_CONVERTER.toWideReadableForm( stackSize ) + "B";
|
||||
|
||||
@@ -206,7 +206,7 @@ public class AppEngInternalInventory extends ItemStackHandler implements Iterabl
|
||||
this.enableClientEvents = enableClientEvents;
|
||||
}
|
||||
|
||||
private IAEAppEngInventory getTileEntity()
|
||||
public IAEAppEngInventory getTileEntity()
|
||||
{
|
||||
return this.te;
|
||||
}
|
||||
|
||||
@@ -164,6 +164,7 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, II
|
||||
|
||||
super.onReady();
|
||||
this.duality.initialize();
|
||||
this.getProxy().setIdlePowerUsage( Math.pow( 4, ( this.getInstalledUpgrades( Upgrades.PATTERN_EXPANSION ) ) ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -554,14 +554,10 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
|
||||
@Override
|
||||
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
|
||||
{
|
||||
if( this.getProxy().isActive() )
|
||||
this.updateHandler();
|
||||
if( this.cellHandler != null && this.cellHandler.getChannel() == channel )
|
||||
{
|
||||
this.updateHandler();
|
||||
|
||||
if( this.cellHandler != null && this.cellHandler.getChannel() == channel )
|
||||
{
|
||||
return Collections.singletonList( this.cellHandler );
|
||||
}
|
||||
return Collections.singletonList( this.cellHandler );
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -692,21 +688,16 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
|
||||
@Override
|
||||
public void postChange( final IBaseMonitor<T> monitor, final Iterable<T> change, final IActionSource source )
|
||||
{
|
||||
if( source == TileChest.this.mySrc || source.machine().map( machine -> machine == TileChest.this ).orElse( false ) )
|
||||
try
|
||||
{
|
||||
try
|
||||
if( TileChest.this.getProxy().isActive() )
|
||||
{
|
||||
if( TileChest.this.getProxy().isActive() )
|
||||
{
|
||||
TileChest.this.getProxy().getStorage().postAlterationOfStoredItems( this.chan, change, TileChest.this.mySrc );
|
||||
}
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
// :(
|
||||
TileChest.this.getProxy().getStorage().postAlterationOfStoredItems( this.chan, change, TileChest.this.mySrc );
|
||||
}
|
||||
} catch ( final GridAccessException e )
|
||||
{
|
||||
// :(
|
||||
}
|
||||
|
||||
TileChest.this.blinkCell( 0 );
|
||||
}
|
||||
|
||||
|
||||
@@ -334,13 +334,8 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
|
||||
@Override
|
||||
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
|
||||
{
|
||||
if( this.getProxy().isActive() )
|
||||
{
|
||||
this.updateState();
|
||||
|
||||
return this.inventoryHandlers.get( channel );
|
||||
}
|
||||
return Collections.emptyList();
|
||||
this.updateState();
|
||||
return this.inventoryHandlers.get( channel );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -20,10 +20,13 @@ package appeng.util;
|
||||
|
||||
|
||||
import appeng.util.inv.*;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.capabilities.IItemRepository;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
@@ -37,12 +40,23 @@ import appeng.api.config.FuzzyMode;
|
||||
*/
|
||||
public abstract class InventoryAdaptor implements Iterable<ItemSlot>
|
||||
{
|
||||
@CapabilityInject( IItemRepository.class)
|
||||
public static Capability<IItemRepository> ITEM_REPOSITORY_CAPABILITY = null;
|
||||
|
||||
public static InventoryAdaptor getAdaptor( final TileEntity te, final EnumFacing d )
|
||||
{
|
||||
if( te != null )
|
||||
{
|
||||
if( te.hasCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d ) )
|
||||
if( ITEM_REPOSITORY_CAPABILITY != null && te.hasCapability( ITEM_REPOSITORY_CAPABILITY, d ) )
|
||||
{
|
||||
IItemRepository itemRepository = te.getCapability( ITEM_REPOSITORY_CAPABILITY, d );
|
||||
if (itemRepository != null){
|
||||
return new AdaptorItemRepository( itemRepository );
|
||||
}
|
||||
}
|
||||
else if( 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 )
|
||||
|
||||
@@ -1246,18 +1246,20 @@ public class Platform
|
||||
if( itemToAdd < input.getStackSize() )
|
||||
{
|
||||
final long original = input.getStackSize();
|
||||
final T leftover = input.copy();
|
||||
final T split = input.copy();
|
||||
split.decStackSize( itemToAdd );
|
||||
input.setStackSize( itemToAdd );
|
||||
split.add( cell.injectItems( input, Actionable.MODULATE, src ) );
|
||||
|
||||
leftover.decStackSize(itemToAdd);
|
||||
split.setStackSize(itemToAdd);
|
||||
leftover.add(cell.injectItems(split, Actionable.MODULATE, src));
|
||||
|
||||
src.player().ifPresent( player ->
|
||||
{
|
||||
final long diff = original - split.getStackSize();
|
||||
final long diff = original - leftover.getStackSize();
|
||||
Stats.ItemsInserted.addToPlayer( player, (int) diff );
|
||||
} );
|
||||
|
||||
return split;
|
||||
return leftover;
|
||||
}
|
||||
|
||||
final T ret = cell.injectItems( input, Actionable.MODULATE, src );
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
|
||||
import appeng.util.Platform;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.capabilities.IItemRepository;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
public class AdaptorItemRepository extends InventoryAdaptor
|
||||
{
|
||||
protected final IItemRepository itemRepository;
|
||||
|
||||
public AdaptorItemRepository( IItemRepository itemRepository )
|
||||
{
|
||||
this.itemRepository = itemRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
|
||||
{
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
|
||||
if( !filter.isEmpty() )
|
||||
{
|
||||
extracted = this.itemRepository.extractItem( filter, amount, true );
|
||||
}
|
||||
else
|
||||
{
|
||||
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() )
|
||||
{
|
||||
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true );
|
||||
if( !extracted.isEmpty() )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
|
||||
if( extracted.isEmpty() || !destination.canInsert( extracted ) )
|
||||
{
|
||||
return rv;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extracted = this.itemRepository.extractItem( filter, amount, false );
|
||||
|
||||
return extracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination )
|
||||
{
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
|
||||
if( !filter.isEmpty() )
|
||||
{
|
||||
extracted = this.itemRepository.extractItem( filter, amount, true );
|
||||
}
|
||||
else
|
||||
{
|
||||
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() )
|
||||
{
|
||||
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true );
|
||||
if( !extracted.isEmpty() )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
|
||||
if( extracted.isEmpty() || !destination.canInsert( extracted ) )
|
||||
{
|
||||
return rv;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return extracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
|
||||
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() )
|
||||
{
|
||||
if( Platform.itemComparisons().isFuzzyEqualItem( record.itemPrototype, filter, fuzzyMode ) )
|
||||
{
|
||||
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true );
|
||||
}
|
||||
|
||||
if( !extracted.isEmpty() )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
|
||||
if( extracted.isEmpty() || !destination.canInsert( extracted ) )
|
||||
{
|
||||
return rv;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extracted = this.itemRepository.extractItem( extracted, amount, false );
|
||||
|
||||
return extracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
|
||||
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() )
|
||||
{
|
||||
if( Platform.itemComparisons().isFuzzyEqualItem( record.itemPrototype, filter, fuzzyMode ) )
|
||||
{
|
||||
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true );
|
||||
}
|
||||
|
||||
if( !extracted.isEmpty() )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
|
||||
if( extracted.isEmpty() || !destination.canInsert( extracted ) )
|
||||
{
|
||||
return rv;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return extracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems( ItemStack toBeAdded )
|
||||
{
|
||||
return this.addItems( toBeAdded, false );
|
||||
}
|
||||
|
||||
protected ItemStack addItems( final ItemStack itemsToAdd, final boolean simulate )
|
||||
{
|
||||
if( itemsToAdd.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
ItemStack left = itemsToAdd.copy();
|
||||
|
||||
left = this.itemRepository.insertItem( left, simulate );
|
||||
|
||||
if( left.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd( ItemStack toBeSimulated )
|
||||
{
|
||||
return this.addItems( toBeSimulated, true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
return !this.itemRepository.getAllItems().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSlots()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,11 +52,9 @@ public class ItemHandlerIterator implements Iterator<ItemSlot>
|
||||
{
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
this.itemSlot.setExtractable( !this.itemHandler.extractItem( this.slot, 1, true ).isEmpty() );
|
||||
this.itemSlot.setExtractable( !this.itemHandler.extractItem( this.slot, Integer.MAX_VALUE, true ).isEmpty() );
|
||||
this.itemSlot.setItemStack( this.itemHandler.getStackInSlot( this.slot ) );
|
||||
this.itemSlot.setSlot( this.slot );
|
||||
this.itemSlot.setSlotLimit( this.itemHandler.getSlotLimit( this.slot ) );
|
||||
this.itemSlot.setItemHandler( this.itemHandler );
|
||||
this.slot++;
|
||||
return this.itemSlot;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
|
||||
public class ItemSlot
|
||||
@@ -35,25 +34,6 @@ public class ItemSlot
|
||||
private IAEItemStack aeItemStack;
|
||||
private ItemStack itemStack;
|
||||
|
||||
public void setItemHandler( IItemHandler itemHandler )
|
||||
{
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
|
||||
private IItemHandler itemHandler;
|
||||
|
||||
public int getSlotLimit()
|
||||
{
|
||||
return slotLimit;
|
||||
}
|
||||
|
||||
public void setSlotLimit( int slotLimit )
|
||||
{
|
||||
this.slotLimit = slotLimit;
|
||||
}
|
||||
|
||||
private int slotLimit;
|
||||
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return this.itemStack
|
||||
@@ -97,19 +77,4 @@ public class ItemSlot
|
||||
{
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
public ItemSlot copy()
|
||||
{
|
||||
ItemSlot copy = new ItemSlot();
|
||||
copy.setSlot( this.slot );
|
||||
copy.setSlotLimit( this.slotLimit );
|
||||
copy.setItemStack( this.getItemStack() );
|
||||
copy.setExtractable( this.isExtractable );
|
||||
copy.setItemHandler( this.itemHandler );
|
||||
return copy;
|
||||
}
|
||||
|
||||
public ItemStack simulateInsertItem( ItemStack sourceItemStack){
|
||||
return this.itemHandler.insertItem( this.slot, sourceItemStack , true );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,294 @@ 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 );
|
||||
if( itemstack.isEmpty() )
|
||||
{
|
||||
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;
|
||||
}
|
||||
final AEItemStack item = AEItemStack.fromItemStack( itemstack );
|
||||
|
||||
@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() );
|
||||
}
|
||||
item.setStackSize(i.getLong(NBT_STACKSIZE));
|
||||
item.setCountRequestable(i.getLong(NBT_REQUESTABLE));
|
||||
item.setCraftable(i.getBoolean(NBT_CRAFTABLE));
|
||||
return item;
|
||||
}
|
||||
|
||||
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;
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound i) {
|
||||
this.getDefinition().writeToNBT( i );
|
||||
|
||||
final ItemStack itemstack = new ItemStack( ByteBufUtils.readTag( data ) );
|
||||
final long stackSize = getPacketValue( stackType, data );
|
||||
final long countRequestable = getPacketValue( countReqType, data );
|
||||
i.setLong(NBT_STACKSIZE, this.getStackSize());
|
||||
i.setLong(NBT_REQUESTABLE, this.getCountRequestable());
|
||||
i.setBoolean(NBT_CRAFTABLE, this.isCraftable());
|
||||
}
|
||||
|
||||
if( itemstack.isEmpty() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
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;
|
||||
|
||||
final AEItemStack item = new AEItemStack( AEItemStackRegistry.getRegisteredStack( itemstack ), stackSize );
|
||||
item.setCountRequestable( countRequestable );
|
||||
item.setCraftable( isCraftable );
|
||||
return item;
|
||||
}
|
||||
final ItemStack itemstack = new ItemStack( ByteBufUtils.readTag( data ) );
|
||||
final long stackSize = getPacketValue( stackType, data );
|
||||
final long countRequestable = getPacketValue( countReqType, data );
|
||||
|
||||
@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 );
|
||||
if( itemstack.isEmpty() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
i.writeByte( mask );
|
||||
ByteBufUtils.writeTag( i, this.getDefinition().serializeNBT() );
|
||||
this.putPacketValue( i, this.getStackSize() );
|
||||
this.putPacketValue( i, this.getCountRequestable() );
|
||||
}
|
||||
final AEItemStack item = new AEItemStack( AEItemStackRegistry.getRegisteredStack( itemstack ), stackSize );
|
||||
item.setCountRequestable( countRequestable );
|
||||
item.setCraftable( isCraftable );
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add( final IAEItemStack option )
|
||||
{
|
||||
if( option == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@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 );
|
||||
|
||||
this.incStackSize( option.getStackSize() );
|
||||
this.setCountRequestable( this.getCountRequestable() + option.getCountRequestable() );
|
||||
this.setCraftable( this.isCraftable() || option.isCraftable() );
|
||||
}
|
||||
i.writeByte( mask );
|
||||
ByteBufUtils.writeTag( i, this.getDefinition().serializeNBT() );
|
||||
this.putPacketValue( i, this.getStackSize() );
|
||||
this.putPacketValue( i, this.getCountRequestable() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fuzzyComparison( final IAEItemStack other, final FuzzyMode mode )
|
||||
{
|
||||
if( mode == FuzzyMode.IGNORE_ALL && OreHelper.INSTANCE.sameOre( this, other ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public void add(final IAEItemStack option) {
|
||||
if (option == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemStack itemStack = this.getDefinition();
|
||||
final ItemStack otherStack = other.getDefinition();
|
||||
this.incStackSize(option.getStackSize());
|
||||
this.setCountRequestable(this.getCountRequestable() + option.getCountRequestable());
|
||||
this.setCraftable(this.isCraftable() || option.isCraftable());
|
||||
}
|
||||
|
||||
return this.fuzzyItemStackComparison( itemStack, otherStack, mode );
|
||||
}
|
||||
@Override
|
||||
public boolean fuzzyComparison(final IAEItemStack other, final FuzzyMode mode) {
|
||||
final ItemStack itemStack = this.getDefinition();
|
||||
final ItemStack otherStack = other.getDefinition();
|
||||
|
||||
@Override
|
||||
public IAEItemStack copy()
|
||||
{
|
||||
return new AEItemStack( this );
|
||||
}
|
||||
return this.fuzzyItemStackComparison(itemStack, otherStack, mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItem()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack copy() {
|
||||
return new AEItemStack(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFluid()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isItem()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel()
|
||||
{
|
||||
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
|
||||
}
|
||||
@Override
|
||||
public boolean isFluid()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack createItemStack()
|
||||
{
|
||||
return ItemHandlerHelper.copyStackWithSize( this.getDefinition(), (int) Math.min( Integer.MAX_VALUE, this.getStackSize() ) );
|
||||
}
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel() {
|
||||
return Api.INSTANCE.storage().getStorageChannel(IItemStorageChannel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getItem()
|
||||
{
|
||||
return this.getDefinition().getItem();
|
||||
}
|
||||
@Override
|
||||
public ItemStack createItemStack() {
|
||||
return ItemHandlerHelper.copyStackWithSize(this.getDefinition(),
|
||||
(int) Math.min(Integer.MAX_VALUE, this.getStackSize()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemDamage()
|
||||
{
|
||||
return this.sharedStack.getItemDamage();
|
||||
}
|
||||
@Override
|
||||
public Item getItem() {
|
||||
return this.getDefinition().getItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sameOre( final IAEItemStack is )
|
||||
{
|
||||
return OreHelper.INSTANCE.sameOre( this, is );
|
||||
}
|
||||
@Override
|
||||
public int getItemDamage() {
|
||||
return this.sharedStack.getItemDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameType( final IAEItemStack otherStack )
|
||||
{
|
||||
if( otherStack == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean sameOre( final IAEItemStack is )
|
||||
{
|
||||
return OreHelper.INSTANCE.sameOre( this, is );
|
||||
}
|
||||
|
||||
return Objects.equals( this.sharedStack, ( (AEItemStack) otherStack ).sharedStack );
|
||||
}
|
||||
@Override
|
||||
public boolean isSameType(final IAEItemStack otherStack) {
|
||||
if (otherStack == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameType( final ItemStack otherStack )
|
||||
{
|
||||
if( otherStack.isEmpty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int oldSize = otherStack.getCount();
|
||||
return Objects.equals(this.sharedStack, ((AEItemStack) otherStack).sharedStack);
|
||||
}
|
||||
|
||||
otherStack.setCount( 1 );
|
||||
boolean ret = ItemStack.areItemStacksEqual( this.getDefinition(), otherStack );
|
||||
otherStack.setCount( oldSize );
|
||||
@Override
|
||||
public boolean isSameType(final ItemStack otherStack) {
|
||||
if (otherStack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
int oldSize = otherStack.getCount();
|
||||
|
||||
return ret;
|
||||
}
|
||||
otherStack.setCount(1);
|
||||
boolean ret = ItemStack.areItemStacksEqual(this.getDefinition(), otherStack);
|
||||
otherStack.setCount(oldSize);
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return this.sharedStack.hashCode();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@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 int hashCode() {
|
||||
return this.sharedStack.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.getStackSize() + "x" + this.getDefinition().getItem().getUnlocalizedName() + "@" + this.getDefinition().getItemDamage();
|
||||
}
|
||||
@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;
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
public List<String> getToolTip()
|
||||
{
|
||||
if( this.tooltip == null )
|
||||
{
|
||||
this.tooltip = Platform.getTooltip( this.asItemStackRepresentation() );
|
||||
}
|
||||
return this.tooltip;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final ItemStack is) {
|
||||
return this.isSameType(is);
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
public String getDisplayName()
|
||||
{
|
||||
if( this.displayName == null )
|
||||
{
|
||||
this.displayName = Platform.getItemDisplayName( this.asItemStackRepresentation() );
|
||||
}
|
||||
return this.displayName;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getStackSize() + "x" + this.getDefinition().getItem().getRegistryName();
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
public String getModID()
|
||||
{
|
||||
if( this.uniqueID == null )
|
||||
{
|
||||
this.uniqueID = Item.REGISTRY.getNameForObject( this.getDefinition().getItem() );
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
public List<String> getToolTip() {
|
||||
if (this.tooltip == null) {
|
||||
this.tooltip = Platform.getTooltip(this.asItemStackRepresentation());
|
||||
}
|
||||
return this.tooltip;
|
||||
}
|
||||
|
||||
if( this.uniqueID == null )
|
||||
{
|
||||
return "** Null";
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getDisplayName() {
|
||||
if (this.displayName == null) {
|
||||
this.displayName = Platform.getItemDisplayName(this.asItemStackRepresentation());
|
||||
}
|
||||
return this.displayName;
|
||||
}
|
||||
|
||||
return this.uniqueID.getResourceDomain() == null ? "** Null" : this.uniqueID.getResourceDomain();
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getModID() {
|
||||
return this.getDefinition().getItem().getRegistryName().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() )
|
||||
{
|
||||
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();
|
||||
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();
|
||||
|
||||
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,192 @@
|
||||
/*
|
||||
* 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 appeng.util.Platform;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import gregtech.common.items.MetaTool;
|
||||
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,198 @@
|
||||
|
||||
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 appeng.util.Platform;
|
||||
import gregtech.common.items.MetaTool;
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public class OreReference
|
||||
return this.otherOptions;
|
||||
}
|
||||
|
||||
List<IAEItemStack> getAEEquivalents()
|
||||
public List<IAEItemStack> getAEEquivalents()
|
||||
{
|
||||
if( this.aeOtherOptions == null )
|
||||
{
|
||||
|
||||
@@ -450,6 +450,7 @@ item.appliedenergistics2.material.basic_card.name=Basic Card
|
||||
item.appliedenergistics2.material.blank_pattern.name=Blank Pattern
|
||||
item.appliedenergistics2.material.calculation_processor.name=Calculation Processor
|
||||
item.appliedenergistics2.material.card_capacity.name=Capacity Card
|
||||
item.appliedenergistics2.material.card_pattern_expansion.name=Pattern Expansion Card
|
||||
item.appliedenergistics2.material.card_fuzzy.name=Fuzzy Card
|
||||
item.appliedenergistics2.material.card_inverter.name=Inverter Card
|
||||
item.appliedenergistics2.material.card_redstone.name=Redstone Card
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "appliedenergistics2:items/material_card_pattern_expansion"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"conditions": [
|
||||
{
|
||||
"type": "forge:and",
|
||||
"values": [
|
||||
{
|
||||
"type": "appliedenergistics2:material_exists",
|
||||
"material": "material.card_capacity"
|
||||
},
|
||||
{
|
||||
"type": "appliedenergistics2:material_exists",
|
||||
"material": "material.basic_card"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"result": {
|
||||
"type": "appliedenergistics2:part",
|
||||
"part": "material.card_pattern_expansion"
|
||||
},
|
||||
"type": "appliedenergistics2:part_shapeless",
|
||||
"ingredients": [
|
||||
{
|
||||
"type": "appliedenergistics2:part",
|
||||
"part": "material.advanced_card"
|
||||
},
|
||||
[
|
||||
{
|
||||
"item": "appliedenergistics2:interface"
|
||||
},
|
||||
{
|
||||
"type": "appliedenergistics2:part",
|
||||
"part": "part.interface"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 6.0 KiB |