Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6f42876963 | |||
| 08952b48dd | |||
| e3c9c4ce65 | |||
| 7b91da58c0 | |||
| 26c06bca15 | |||
| 4458bd28ab | |||
| df3f00d978 | |||
| 18ae994ee4 | |||
| 47888b5546 | |||
| 9b9579b358 | |||
| 52da4f9528 | |||
| 50aac2c768 | |||
| 33946438bd | |||
| 9372cb2f14 | |||
| 00037ace77 | |||
| e13af643ba | |||
| ffcfd809d8 | |||
| 7c10a6b883 | |||
| c2bddc30c4 | |||
| 024655f84d | |||
| 589e48ac01 | |||
| 43d3a2c1c0 | |||
| c432fa7200 | |||
| cc744ab8b9 | |||
| 8fe4229a8e | |||
| 3f86884965 | |||
| 1319ec79c9 |
+47
@@ -0,0 +1,47 @@
|
|||||||
|
Changes so far :
|
||||||
|
|
||||||
|
Design changes/breakages:
|
||||||
|
- Interfaces no longer spill items of one pattern on other faces
|
||||||
|
- Interfaces now push patterns in round-robin (Interfaces, then sides)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Fixes:
|
||||||
|
|
||||||
|
- Fix gregtech machines appearing with 'unnamed' or 'draconium lens' on the interface terminal on specific situations.
|
||||||
|
- Add memorycard support for fluid interfaces, import/export/storage busses and level emitters ( this fix was upstreamed to AE2 for MC 1.16)
|
||||||
|
- Storage busses now hide/show inaccessible items as configured.
|
||||||
|
- Exclusive Blocking mode for GTCE ( shapes, molds and configured circuits do not block GTCE machines )
|
||||||
|
- Blocking modes default to block on any item in the iventory the entity exposes
|
||||||
|
- Fuzzy includes items that report that they're damageable, but report a maxDamage of 0 ( auto-crafting of basic capacitors -> resonant capacitors is now possible ) <- Broken item implementation.
|
||||||
|
|
||||||
|
Performance:
|
||||||
|
|
||||||
|
- Added @talchas fixes for insane channelless AE networks.
|
||||||
|
- Implemented StorageDrawers slotless itemrepository.
|
||||||
|
- Removed CraftedEvent calls (really bad lag with craftweaker versions before CraftTweaker2-1.12-4.1.20.626)
|
||||||
|
- Count items set in interfaces before queuing crafting for them needlessly
|
||||||
|
- Backported b7ca98d ( Avoid copying items on simulated item extraction )
|
||||||
|
- Cache some level emitters functions
|
||||||
|
|
||||||
|
QOL:
|
||||||
|
|
||||||
|
- added highlight interface button to interface terminal ("?" button on the left of the interface slots)
|
||||||
|
- Added bar on the interface terminal that search by inputs ( The one on the LEFT, also searchs by interface name )
|
||||||
|
- Shortcut to molecular assemblers with free slots on the terminal interface by @Theisyat
|
||||||
|
- Toggle button on interface terminal to hide full interfaces
|
||||||
|
- JEI "U""R" and "A" (Usages/Recipes/Bookmark) now work on the Crafting Status GUI. ( the one that shows the total items to craft, and whats missing)
|
||||||
|
- Patterns can now be made with items currently showing on JEI. ( This is overriden by Just Enough Energistics. )
|
||||||
|
- Added multiplier buttons to processing pattern gui
|
||||||
|
- Switched crafting terminal JEI search to fuzzy mode. If the recipe uses a damageable item, AE will try to grab it ( damaged tools )
|
||||||
|
- Encoded patterns stack up to 64 ( holding shift and clicking the encode arrow will transfer the encoded pattern to the player inventory)
|
||||||
|
- Encoded patterns can be draggred on the interface terminal.
|
||||||
|
- Storage Monitor and Conversion Monitor now also ccepts fluids
|
||||||
|
- Draggable JEI ghost items (also works on bookmarked items. SHIFT + Click will move the hovered item into the first free target slot)
|
||||||
|
-JEI auto switches between crafting and processing patterns
|
||||||
|
|
||||||
|
HOTKEYS:
|
||||||
|
|
||||||
|
- Implemented mousetweaks API. AE2 custom keybinds now work. (Try right clicking and use the scroll-wheel on the terminals)
|
||||||
|
- Holding SHIFT and scrolling UP and DOWN will increase the items set on the configured slots of Interfaces and Pattern Terminal (Processing mode)
|
||||||
@@ -19,11 +19,6 @@
|
|||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
|
|
||||||
maven {
|
|
||||||
name = "storagedrawers"
|
|
||||||
url = "https://dl.bintray.com/jaquadro/dev/"
|
|
||||||
}
|
|
||||||
|
|
||||||
maven {
|
maven {
|
||||||
name "Mobius"
|
name "Mobius"
|
||||||
url "http://mobiusstrip.eu/maven"
|
url "http://mobiusstrip.eu/maven"
|
||||||
@@ -39,6 +34,11 @@ repositories {
|
|||||||
url "http://maven.mcmoddev.com"
|
url "http://maven.mcmoddev.com"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maven {
|
||||||
|
name "Ellpeck"
|
||||||
|
url "https://maven.ellpeck.de"
|
||||||
|
}
|
||||||
|
|
||||||
maven {
|
maven {
|
||||||
name = "IC2 repo"
|
name = "IC2 repo"
|
||||||
url = "http://maven.ic2.player.to"
|
url = "http://maven.ic2.player.to"
|
||||||
@@ -59,11 +59,6 @@ repositories {
|
|||||||
url "http://maven.k-4u.nl/"
|
url "http://maven.k-4u.nl/"
|
||||||
}
|
}
|
||||||
|
|
||||||
maven { // Hwyla
|
|
||||||
name 'tehnut'
|
|
||||||
url "http://tehnut.info/maven"
|
|
||||||
}
|
|
||||||
|
|
||||||
maven { // CraftTweaker
|
maven { // CraftTweaker
|
||||||
name 'jared maven'
|
name 'jared maven'
|
||||||
url "http://maven.blamejared.com/"
|
url "http://maven.blamejared.com/"
|
||||||
@@ -102,6 +97,7 @@ dependencies {
|
|||||||
compileOnly "CraftTweaker2:CraftTweaker2-API:${crafttweaker_version}"
|
compileOnly "CraftTweaker2:CraftTweaker2-API:${crafttweaker_version}"
|
||||||
compileOnly "inventory-tweaks:InventoryTweaks:${inventorytweaks_version}:api"
|
compileOnly "inventory-tweaks:InventoryTweaks:${inventorytweaks_version}:api"
|
||||||
compileOnly "team.chisel.ctm:CTM:${ctm_version}"
|
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
|
// at runtime, use the full JEI jar
|
||||||
runtime "mezz.jei:jei_${minecraft_version}:${jei_version}"
|
runtime "mezz.jei:jei_${minecraft_version}:${jei_version}"
|
||||||
|
|||||||
@@ -112,4 +112,13 @@ public interface IAEItemStack extends IAEStack<IAEItemStack>
|
|||||||
* @return definition stack
|
* @return definition stack
|
||||||
*/
|
*/
|
||||||
ItemStack getDefinition();
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -25,6 +25,7 @@ import java.util.*;
|
|||||||
import appeng.api.config.ActionItems;
|
import appeng.api.config.ActionItems;
|
||||||
import appeng.api.config.Settings;
|
import appeng.api.config.Settings;
|
||||||
import appeng.client.gui.widgets.GuiImgButton;
|
import appeng.client.gui.widgets.GuiImgButton;
|
||||||
|
import appeng.core.worlddata.IWorldPlayerMapping;
|
||||||
import appeng.util.BlockPosUtils;
|
import appeng.util.BlockPosUtils;
|
||||||
import com.google.common.collect.HashMultimap;
|
import com.google.common.collect.HashMultimap;
|
||||||
|
|
||||||
@@ -49,6 +50,7 @@ import appeng.util.Platform;
|
|||||||
import net.minecraft.nbt.NBTUtil;
|
import net.minecraft.nbt.NBTUtil;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.text.TextComponentString;
|
import net.minecraft.util.text.TextComponentString;
|
||||||
|
import net.minecraftforge.common.DimensionManager;
|
||||||
import org.lwjgl.input.Mouse;
|
import org.lwjgl.input.Mouse;
|
||||||
|
|
||||||
|
|
||||||
@@ -79,6 +81,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
|||||||
private PartInterfaceTerminal partInterfaceTerminal;
|
private PartInterfaceTerminal partInterfaceTerminal;
|
||||||
private GuiButton guiButtonHide;
|
private GuiButton guiButtonHide;
|
||||||
private GuiButton guiButtonNextAssembler;
|
private GuiButton guiButtonNextAssembler;
|
||||||
|
private HashMap<ClientDCInternalInv,Integer> dimHashMap = new HashMap<>();
|
||||||
|
|
||||||
public GuiInterfaceTerminal( final InventoryPlayer inventoryPlayer, final PartInterfaceTerminal te )
|
public GuiInterfaceTerminal( final InventoryPlayer inventoryPlayer, final PartInterfaceTerminal te )
|
||||||
{
|
{
|
||||||
@@ -217,9 +220,17 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
|||||||
{
|
{
|
||||||
BlockPos blockPos = blockPosHashMap.get( guiButtonHashMap.get( this.selectedButton ) );
|
BlockPos blockPos = blockPosHashMap.get( guiButtonHashMap.get( this.selectedButton ) );
|
||||||
BlockPos blockPos2 = mc.player.getPosition();
|
BlockPos blockPos2 = mc.player.getPosition();
|
||||||
int dimension = mc.world.provider.getDimension();
|
int playerDim = mc.world.provider.getDimension();
|
||||||
hilightBlock( blockPos, System.currentTimeMillis() + 500 * BlockPosUtils.getDistance(blockPos, blockPos2), dimension );
|
int interfaceDim = dimHashMap.get( guiButtonHashMap.get( this.selectedButton ) );
|
||||||
mc.player.sendStatusMessage( new TextComponentString( "The interface is now highlighted at " + "X: " + blockPos.getX() + " Y: " + blockPos.getY() + " Z: " + blockPos.getZ() ), false );
|
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();
|
mc.player.closeScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,6 +336,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
|||||||
final NBTTagCompound invData = in.getCompoundTag( key );
|
final NBTTagCompound invData = in.getCompoundTag( key );
|
||||||
final ClientDCInternalInv current = this.getById( id, invData.getLong( "sortBy" ), invData.getString( "un" ) );
|
final ClientDCInternalInv current = this.getById( id, invData.getLong( "sortBy" ), invData.getString( "un" ) );
|
||||||
blockPosHashMap.put( current, NBTUtil.getPosFromTag( invData.getCompoundTag( "pos" )) );
|
blockPosHashMap.put( current, NBTUtil.getPosFromTag( invData.getCompoundTag( "pos" )) );
|
||||||
|
dimHashMap.put( current, invData.getInteger( "dim" ));
|
||||||
|
|
||||||
for( int x = 0; x < current.getInventory().getSlots(); x++ )
|
for( int x = 0; x < current.getInventory().getSlots(); x++ )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -159,56 +159,58 @@ public class ContainerCraftingCPU extends AEBaseContainer implements IMEMonitorH
|
|||||||
@Override
|
@Override
|
||||||
public void detectAndSendChanges()
|
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 PacketMEInventoryUpdate a = new PacketMEInventoryUpdate( (byte) 0 );
|
||||||
final double remainingItems = this.getMonitor().getRemainingItemCount();
|
final PacketMEInventoryUpdate b = new PacketMEInventoryUpdate( (byte) 1 );
|
||||||
final double startItems = this.getMonitor().getStartItemCount();
|
final PacketMEInventoryUpdate c = new PacketMEInventoryUpdate( (byte) 2 );
|
||||||
final long eta = (long) ( elapsedTime / Math.max( 1d, ( startItems - remainingItems ) ) * remainingItems );
|
|
||||||
this.setEstimatedTime( eta );
|
|
||||||
}
|
|
||||||
|
|
||||||
final PacketMEInventoryUpdate a = new PacketMEInventoryUpdate( (byte) 0 );
|
for( final IAEItemStack out : this.list )
|
||||||
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 )
|
|
||||||
{
|
{
|
||||||
if( !a.isEmpty() )
|
a.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.STORAGE ) );
|
||||||
{
|
b.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.ACTIVE ) );
|
||||||
NetworkHandler.instance().sendTo( a, (EntityPlayerMP) g );
|
c.appendItem( this.getMonitor().getItemStack( out, CraftingItemList.PENDING ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !b.isEmpty() )
|
this.list.resetStatus();
|
||||||
{
|
|
||||||
NetworkHandler.instance().sendTo( b, (EntityPlayerMP) g );
|
|
||||||
}
|
|
||||||
|
|
||||||
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 )
|
||||||
catch( final IOException e )
|
{
|
||||||
{
|
// :P
|
||||||
// :P
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
super.detectAndSendChanges();
|
super.detectAndSendChanges();
|
||||||
|
|||||||
@@ -403,7 +403,8 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer
|
|||||||
{
|
{
|
||||||
tag.setLong( "sortBy", inv.sortBy );
|
tag.setLong( "sortBy", inv.sortBy );
|
||||||
tag.setString( "un", inv.unlocalizedName );
|
tag.setString( "un", inv.unlocalizedName );
|
||||||
tag.setTag("pos", NBTUtil.createPosTag( inv.pos ) );
|
tag.setTag( "pos", NBTUtil.createPosTag( inv.pos ) );
|
||||||
|
tag.setInteger( "dim", inv.dim );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int x = 0; x < length; x++ )
|
for( int x = 0; x < length; x++ )
|
||||||
@@ -435,6 +436,7 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer
|
|||||||
private final IItemHandler client;
|
private final IItemHandler client;
|
||||||
private final IItemHandler server;
|
private final IItemHandler server;
|
||||||
private final BlockPos pos;
|
private final BlockPos pos;
|
||||||
|
private final int dim;
|
||||||
|
|
||||||
public InvTracker( final DualityInterface dual, final IItemHandler patterns, final String unlocalizedName )
|
public InvTracker( final DualityInterface dual, final IItemHandler patterns, final String unlocalizedName )
|
||||||
{
|
{
|
||||||
@@ -443,6 +445,7 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer
|
|||||||
this.unlocalizedName = unlocalizedName;
|
this.unlocalizedName = unlocalizedName;
|
||||||
this.sortBy = dual.getSortValue();
|
this.sortBy = dual.getSortValue();
|
||||||
this.pos = dual.getLocation().getPos();
|
this.pos = dual.getLocation().getPos();
|
||||||
|
this.dim = dual.getLocation().getWorld().provider.getDimension();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import appeng.container.slot.*;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
@@ -51,12 +52,6 @@ import appeng.api.storage.data.IAEItemStack;
|
|||||||
import appeng.api.storage.data.IItemList;
|
import appeng.api.storage.data.IItemList;
|
||||||
import appeng.container.ContainerNull;
|
import appeng.container.ContainerNull;
|
||||||
import appeng.container.guisync.GuiSync;
|
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.core.sync.packets.PacketPatternSlot;
|
||||||
import appeng.helpers.IContainerCraftingPacket;
|
import appeng.helpers.IContainerCraftingPacket;
|
||||||
import appeng.items.storage.ItemViewCell;
|
import appeng.items.storage.ItemViewCell;
|
||||||
@@ -132,6 +127,28 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
|
|||||||
this.updateOrderOfOutputSlots();
|
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()
|
private void updateOrderOfOutputSlots()
|
||||||
{
|
{
|
||||||
if( !this.isCraftingMode() )
|
if( !this.isCraftingMode() )
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package appeng.core.sync.packets;
|
|||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
import appeng.api.storage.data.IAEFluidStack;
|
import appeng.api.storage.data.IAEFluidStack;
|
||||||
import appeng.container.slot.IJEITargetSlot;
|
import appeng.container.slot.IJEITargetSlot;
|
||||||
@@ -224,7 +225,9 @@ public class PacketInventoryAction extends AppEngPacket
|
|||||||
IAEFluidStack aefs = AEFluidStack.fromNBT( this.slotItem.getDefinition().getTagCompound() );
|
IAEFluidStack aefs = AEFluidStack.fromNBT( this.slotItem.getDefinition().getTagCompound() );
|
||||||
if( aefs != null )
|
if( aefs != null )
|
||||||
{
|
{
|
||||||
|
aefs.setStackSize( 1000 );
|
||||||
( (ContainerFluidConfigurable) sender.openContainer ).getFluidConfigInventory().setFluidInSlot( this.slot, aefs );
|
( (ContainerFluidConfigurable) sender.openContainer ).getFluidConfigInventory().setFluidInSlot( this.slot, aefs );
|
||||||
|
NetworkHandler.instance().sendToServer( new PacketFluidSlot( Collections.singletonMap( this.slot, aefs ) ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ public class PacketJEIRecipe extends AppEngPacket
|
|||||||
IAEItemStack mostDamaged = null;
|
IAEItemStack mostDamaged = null;
|
||||||
for( IAEItemStack is : outList )
|
for( IAEItemStack is : outList )
|
||||||
{
|
{
|
||||||
if( !is.isCraftable() && is.getItem().isDamageable() )
|
if( !is.isCraftable() )
|
||||||
{
|
{
|
||||||
if( mostDamaged == null || mostDamaged.getItemDamage() < is.getItemDamage() )
|
if( mostDamaged == null || mostDamaged.getItemDamage() < is.getItemDamage() )
|
||||||
{
|
{
|
||||||
@@ -285,6 +285,7 @@ public class PacketJEIRecipe extends AppEngPacket
|
|||||||
IItemHandler outputSlots = cct.getInventoryByName( "output" );
|
IItemHandler outputSlots = cct.getInventoryByName( "output" );
|
||||||
for( int i = 0; i < this.output.length; ++i )
|
for( int i = 0; i < this.output.length; ++i )
|
||||||
{
|
{
|
||||||
|
if( this.output[i] == null ) continue;
|
||||||
ItemHandlerUtil.setStackInSlot( outputSlots, i, this.output[i] );
|
ItemHandlerUtil.setStackInSlot( outputSlots, i, this.output[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ import appeng.api.storage.IStorageChannel;
|
|||||||
import appeng.api.storage.channels.IItemStorageChannel;
|
import appeng.api.storage.channels.IItemStorageChannel;
|
||||||
import appeng.api.storage.data.IAEItemStack;
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
import appeng.api.storage.data.IItemList;
|
import appeng.api.storage.data.IItemList;
|
||||||
|
import appeng.me.helpers.PlayerSource;
|
||||||
import appeng.util.inv.ItemListIgnoreCrafting;
|
import appeng.util.inv.ItemListIgnoreCrafting;
|
||||||
|
import net.minecraft.util.text.TextComponentString;
|
||||||
|
|
||||||
|
|
||||||
public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
||||||
@@ -307,8 +309,15 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
|
|||||||
|
|
||||||
if( result == null || result.getStackSize() != extra.getStackSize() )
|
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;
|
failed = true;
|
||||||
break;
|
if( !src.player().isPresent() ) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,12 @@ import appeng.util.*;
|
|||||||
import appeng.util.inv.*;
|
import appeng.util.inv.*;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.api.tile.IPhantomTile;
|
||||||
import gregtech.api.block.machines.BlockMachine;
|
import gregtech.api.block.machines.BlockMachine;
|
||||||
import gregtech.api.metatileentity.MetaTileEntity;
|
import gregtech.api.metatileentity.MetaTileEntity;
|
||||||
|
import gregtech.api.metatileentity.MetaTileEntityHolder;
|
||||||
|
import gregtech.api.metatileentity.TieredMetaTileEntity;
|
||||||
|
import gregtech.api.metatileentity.WorkableTieredMetaTileEntity;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.init.Items;
|
import net.minecraft.init.Items;
|
||||||
@@ -1095,16 +1099,31 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
|||||||
{
|
{
|
||||||
if( this.isBlocking() )
|
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() );
|
phantomTE = ( (IPhantomTile) te );
|
||||||
if( GTad != null && !invIsBlockedGTCE( GTad ) )
|
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 );
|
visitedFaces.remove( s );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( invIsBlocked( ad ) )
|
|
||||||
|
else if( invIsBlocked( ad ) )
|
||||||
{
|
{
|
||||||
visitedFaces.remove( s );
|
visitedFaces.remove( s );
|
||||||
continue;
|
continue;
|
||||||
@@ -1152,19 +1171,34 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
|||||||
for( final EnumFacing s : possibleDirections )
|
for( final EnumFacing s : possibleDirections )
|
||||||
{
|
{
|
||||||
final TileEntity te = w.getTileEntity( tile.getPos().offset( s ) );
|
final TileEntity te = w.getTileEntity( tile.getPos().offset( s ) );
|
||||||
|
IPhantomTile phantomTE = null;
|
||||||
|
|
||||||
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor( te, s.getOpposite() );
|
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor( te, s.getOpposite() );
|
||||||
if( ad != null )
|
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() );
|
phantomTE = ( (IPhantomTile) te );
|
||||||
if( GTad != null && !invIsBlockedGTCE( GTad ) )
|
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;
|
allAreBusy = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if( !invIsBlocked( ad ) )
|
else if( !invIsBlocked( ad ) )
|
||||||
{
|
{
|
||||||
allAreBusy = false;
|
allAreBusy = false;
|
||||||
@@ -1177,6 +1211,12 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
|
|||||||
return busy;
|
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
|
private boolean sameGrid( final IGrid grid ) throws GridAccessException
|
||||||
{
|
{
|
||||||
return grid == this.gridProxy.getGrid();
|
return grid == this.gridProxy.getGrid();
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ public class HighlighterHandler
|
|||||||
tessellator.draw();
|
tessellator.draw();
|
||||||
|
|
||||||
GlStateManager.enableTexture2D();
|
GlStateManager.enableTexture2D();
|
||||||
|
GlStateManager.enableDepth();
|
||||||
GlStateManager.popMatrix();
|
GlStateManager.popMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import java.util.Map;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import appeng.container.implementations.ContainerPatternTerm;
|
import appeng.container.implementations.ContainerPatternTerm;
|
||||||
|
import appeng.core.sync.packets.PacketValueConfig;
|
||||||
import mezz.jei.api.recipe.VanillaRecipeCategoryUid;
|
import mezz.jei.api.recipe.VanillaRecipeCategoryUid;
|
||||||
import mezz.jei.transfer.RecipeTransferErrorInternal;
|
import mezz.jei.transfer.RecipeTransferErrorInternal;
|
||||||
import mezz.jei.transfer.RecipeTransferErrorTooltip;
|
import mezz.jei.transfer.RecipeTransferErrorTooltip;
|
||||||
@@ -73,24 +74,7 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
|
|||||||
{
|
{
|
||||||
final String recipeType = recipeLayout.getRecipeCategory().getUid();
|
final String recipeType = recipeLayout.getRecipeCategory().getUid();
|
||||||
|
|
||||||
if (!recipeType.equals( VanillaRecipeCategoryUid.INFORMATION) && !recipeType.equals(VanillaRecipeCategoryUid.FUEL))
|
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
|
|
||||||
{
|
{
|
||||||
return RecipeTransferErrorInternal.INSTANCE;
|
return RecipeTransferErrorInternal.INSTANCE;
|
||||||
}
|
}
|
||||||
@@ -100,6 +84,30 @@ class RecipeTransferHandler<T extends Container> implements IRecipeTransferHandl
|
|||||||
return null;
|
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();
|
Map<Integer, ? extends IGuiIngredient<ItemStack>> ingredients = recipeLayout.getItemStacks().getGuiIngredients();
|
||||||
|
|
||||||
final NBTTagCompound recipe = new NBTTagCompound();
|
final NBTTagCompound recipe = new NBTTagCompound();
|
||||||
|
|||||||
@@ -633,10 +633,10 @@ public class GridNode implements IGridNode, IPathItem
|
|||||||
this.usedChannels = 0;
|
this.usedChannels = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int idx = this.connections.indexOf( fast );
|
final int idx = this.connections.indexOf( (IGridConnection) fast );
|
||||||
if( idx > 0 )
|
if( idx > 0 )
|
||||||
{
|
{
|
||||||
this.connections.remove( fast );
|
this.connections.remove( (IGridConnection) fast );
|
||||||
this.connections.add( 0, (IGridConnection) fast );
|
this.connections.add( 0, (IGridConnection) fast );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-10
@@ -42,6 +42,10 @@ import com.google.common.collect.ImmutableList;
|
|||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Multimap;
|
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 net.minecraft.world.World;
|
||||||
|
|
||||||
import appeng.api.AEApi;
|
import appeng.api.AEApi;
|
||||||
@@ -105,8 +109,8 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
|||||||
private final Set<ICraftingProvider> craftingProviders = new HashSet<>();
|
private final Set<ICraftingProvider> craftingProviders = new HashSet<>();
|
||||||
private final Map<IGridNode, ICraftingWatcher> craftingWatchers = new HashMap<>();
|
private final Map<IGridNode, ICraftingWatcher> craftingWatchers = new HashMap<>();
|
||||||
private final IGrid grid;
|
private final IGrid grid;
|
||||||
private final Map<ICraftingPatternDetails, List<ICraftingMedium>> craftingMethods = new HashMap<>();
|
private final Object2ObjectMap<ICraftingPatternDetails, List<ICraftingMedium>> craftingMethods = new Object2ObjectOpenHashMap<>();
|
||||||
private final Map<IAEItemStack, ImmutableList<ICraftingPatternDetails>> craftableItems = new HashMap<>();
|
private final Object2ObjectMap<IAEItemStack, ImmutableList<ICraftingPatternDetails>> craftableItems = new Object2ObjectOpenHashMap<>();
|
||||||
private final Set<IAEItemStack> emitableItems = new HashSet<>();
|
private final Set<IAEItemStack> emitableItems = new HashSet<>();
|
||||||
private final Map<String, CraftingLinkNexus> craftingLinks = new HashMap<>();
|
private final Map<String, CraftingLinkNexus> craftingLinks = new HashMap<>();
|
||||||
private final Multimap<IAEStack, CraftingWatcher> interests = HashMultimap.create();
|
private final Multimap<IAEStack, CraftingWatcher> interests = HashMultimap.create();
|
||||||
@@ -160,11 +164,11 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
|||||||
{
|
{
|
||||||
if( machine instanceof ICraftingWatcherHost )
|
if( machine instanceof ICraftingWatcherHost )
|
||||||
{
|
{
|
||||||
final ICraftingWatcher craftingWatcher = this.craftingWatchers.get( machine );
|
final ICraftingWatcher craftingWatcher = this.craftingWatchers.get( gridNode );
|
||||||
if( craftingWatcher != null )
|
if( craftingWatcher != null )
|
||||||
{
|
{
|
||||||
craftingWatcher.reset();
|
craftingWatcher.reset();
|
||||||
this.craftingWatchers.remove( machine );
|
this.craftingWatchers.remove( gridNode );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,7 +274,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Map<IAEItemStack, ImmutableList<ICraftingPatternDetails>> oldItems = this.craftableItems;
|
final Object2ObjectMap<IAEItemStack, ImmutableList<ICraftingPatternDetails>> oldItems = this.craftableItems;
|
||||||
|
|
||||||
// erase list.
|
// erase list.
|
||||||
this.craftingMethods.clear();
|
this.craftingMethods.clear();
|
||||||
@@ -287,7 +291,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
|||||||
provider.provideCrafting( this );
|
provider.provideCrafting( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
final Map<IAEItemStack, Set<ICraftingPatternDetails>> tmpCraft = new HashMap<>();
|
final Object2ObjectMap<IAEItemStack, ObjectSet<ICraftingPatternDetails>> tmpCraft = new Object2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
// new craftables!
|
// new craftables!
|
||||||
for( final ICraftingPatternDetails details : this.craftingMethods.keySet() )
|
for( final ICraftingPatternDetails details : this.craftingMethods.keySet() )
|
||||||
@@ -298,11 +302,11 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
|||||||
out.reset();
|
out.reset();
|
||||||
out.setCraftable( true );
|
out.setCraftable( true );
|
||||||
|
|
||||||
Set<ICraftingPatternDetails> methods = tmpCraft.get( out );
|
ObjectSet<ICraftingPatternDetails> methods = tmpCraft.get( out );
|
||||||
|
|
||||||
if( methods == null )
|
if( methods == null )
|
||||||
{
|
{
|
||||||
tmpCraft.put( out, methods = new TreeSet<>( COMPARATOR ) );
|
tmpCraft.put( out, methods = new ObjectRBTreeSet<>( COMPARATOR ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
methods.add( details );
|
methods.add( details );
|
||||||
@@ -310,7 +314,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
// make them immutable
|
// 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() ) );
|
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 )
|
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()
|
public GenericInterestManager<CraftingWatcher> getInterestManager()
|
||||||
|
|||||||
+153
-24
@@ -30,6 +30,7 @@ import java.util.PriorityQueue;
|
|||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.HashMultiset;
|
import com.google.common.collect.HashMultiset;
|
||||||
import com.google.common.collect.Multiset;
|
import com.google.common.collect.Multiset;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
@@ -63,7 +64,7 @@ import appeng.me.energy.EnergyWatcher;
|
|||||||
public class EnergyGridCache implements IEnergyGrid
|
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(),
|
private static final Comparator<IEnergyGridProvider> COMPARATOR_HIGHEST_AMOUNT_STORED_FIRST = ( o1, o2 ) -> Double.compare( o2.getProviderStoredEnergy(),
|
||||||
o1.getProviderStoredEnergy() );
|
o1.getProviderStoredEnergy() );
|
||||||
|
|
||||||
@@ -76,9 +77,24 @@ public class EnergyGridCache implements IEnergyGrid
|
|||||||
};
|
};
|
||||||
|
|
||||||
private final NavigableSet<EnergyThreshold> interests = Sets.newTreeSet();
|
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 double averageLength = 40.0;
|
||||||
private final Set<IAEPowerStorage> providers = new LinkedHashSet<>();
|
private final Set<IAEPowerStorage> providers = new LinkedHashSet<>();
|
||||||
|
// Used to track whether an extraction is currently in progress, to fail fast
|
||||||
|
// when something externally
|
||||||
|
// modifies the energy grid.
|
||||||
|
private boolean ongoingExtractOperation = false;
|
||||||
|
|
||||||
|
// Should only be modified from the add/remove methods below to guard against
|
||||||
|
// concurrent modifications
|
||||||
private final Set<IAEPowerStorage> requesters = new LinkedHashSet<>();
|
private final Set<IAEPowerStorage> requesters = new LinkedHashSet<>();
|
||||||
|
// Used to track whether an injection is currently in progress, to fail fast
|
||||||
|
// when something externally
|
||||||
|
// modifies the energy grid.
|
||||||
|
private boolean ongoingInjectOperation = false;
|
||||||
|
|
||||||
private final Multiset<IEnergyGridProvider> energyGridProviders = HashMultiset.create();
|
private final Multiset<IEnergyGridProvider> energyGridProviders = HashMultiset.create();
|
||||||
private final IGrid myGrid;
|
private final IGrid myGrid;
|
||||||
private final HashMap<IGridNode, IEnergyWatcher> watchers = new HashMap<>();
|
private final HashMap<IGridNode, IEnergyWatcher> watchers = new HashMap<>();
|
||||||
@@ -110,6 +126,10 @@ public class EnergyGridCache implements IEnergyGrid
|
|||||||
private double lastStoredPower = -1;
|
private double lastStoredPower = -1;
|
||||||
|
|
||||||
private final GridPowerStorage localStorage = new GridPowerStorage();
|
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 )
|
public EnergyGridCache( final IGrid g )
|
||||||
{
|
{
|
||||||
@@ -143,18 +163,32 @@ public class EnergyGridCache implements IEnergyGrid
|
|||||||
{
|
{
|
||||||
if( ev.storage.isAEPublicPowerStorage() )
|
if( ev.storage.isAEPublicPowerStorage() )
|
||||||
{
|
{
|
||||||
switch( ev.type )
|
switch ( ev.type )
|
||||||
{
|
{
|
||||||
case PROVIDE_POWER:
|
case PROVIDE_POWER:
|
||||||
if( ev.storage.getPowerFlow() != AccessRestriction.WRITE )
|
if( ev.storage.getPowerFlow() != AccessRestriction.WRITE )
|
||||||
{
|
{
|
||||||
this.providers.add( ev.storage );
|
if( !ongoingExtractOperation )
|
||||||
|
{
|
||||||
|
addProvider( ev.storage );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.providersToAdd.add( ev.storage );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case REQUEST_POWER:
|
case REQUEST_POWER:
|
||||||
if( ev.storage.getPowerFlow() != AccessRestriction.READ )
|
if( ev.storage.getPowerFlow() != AccessRestriction.READ )
|
||||||
{
|
{
|
||||||
this.requesters.add( ev.storage );
|
if( !ongoingInjectOperation )
|
||||||
|
{
|
||||||
|
addRequester( ev.storage );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.requesterToAdd.add( ev.storage );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -168,6 +202,23 @@ public class EnergyGridCache implements IEnergyGrid
|
|||||||
@Override
|
@Override
|
||||||
public void onUpdateTick()
|
public void onUpdateTick()
|
||||||
{
|
{
|
||||||
|
if (!providerToRemove.isEmpty() && !ongoingExtractOperation) {
|
||||||
|
this.providers.removeIf( p -> providerToRemove.contains( p ) );
|
||||||
|
providerToRemove.clear();
|
||||||
|
}
|
||||||
|
if (!requesterToRemove.isEmpty() && !ongoingInjectOperation) {
|
||||||
|
this.requesters.removeIf( r -> providerToRemove.contains( r ) );
|
||||||
|
requesterToRemove.clear();
|
||||||
|
}
|
||||||
|
if (!providersToAdd.isEmpty() && !ongoingExtractOperation) {
|
||||||
|
this.providers.addAll(providersToAdd);
|
||||||
|
providersToAdd.clear();
|
||||||
|
}
|
||||||
|
if( !requesterToAdd.isEmpty() && !ongoingInjectOperation){
|
||||||
|
this.requesters.addAll(requesterToAdd);
|
||||||
|
requesterToAdd.clear();
|
||||||
|
}
|
||||||
|
|
||||||
if( !this.interests.isEmpty() )
|
if( !this.interests.isEmpty() )
|
||||||
{
|
{
|
||||||
final double oldPower = this.lastStoredPower;
|
final double oldPower = this.lastStoredPower;
|
||||||
@@ -303,18 +354,30 @@ public class EnergyGridCache implements IEnergyGrid
|
|||||||
|
|
||||||
final Iterator<IAEPowerStorage> it = this.providers.iterator();
|
final Iterator<IAEPowerStorage> it = this.providers.iterator();
|
||||||
|
|
||||||
while( extractedPower < amt && it.hasNext() )
|
ongoingExtractOperation = true;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
final IAEPowerStorage node = it.next();
|
while ( extractedPower < amt && it.hasNext() )
|
||||||
|
|
||||||
final double req = amt - extractedPower;
|
|
||||||
final double newPower = node.extractAEPower( req, mode, PowerMultiplier.ONE );
|
|
||||||
extractedPower += newPower;
|
|
||||||
|
|
||||||
if( newPower < req && mode == Actionable.MODULATE )
|
|
||||||
{
|
{
|
||||||
it.remove();
|
final IAEPowerStorage node = it.next();
|
||||||
|
|
||||||
|
if ( providerToRemove.contains( node )) {
|
||||||
|
it.remove();
|
||||||
|
providerToRemove.remove( node );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
final double req = amt - extractedPower;
|
||||||
|
final double newPower = node.extractAEPower( req, mode, PowerMultiplier.ONE );
|
||||||
|
extractedPower += newPower;
|
||||||
|
|
||||||
|
if( newPower < req && mode == Actionable.MODULATE )
|
||||||
|
{
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
ongoingExtractOperation = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final double result = Math.min( extractedPower, amt );
|
final double result = Math.min( extractedPower, amt );
|
||||||
@@ -340,15 +403,29 @@ public class EnergyGridCache implements IEnergyGrid
|
|||||||
|
|
||||||
final Iterator<IAEPowerStorage> it = this.requesters.iterator();
|
final Iterator<IAEPowerStorage> it = this.requesters.iterator();
|
||||||
|
|
||||||
while( amt > 0 && it.hasNext() )
|
ongoingInjectOperation = true;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
final IAEPowerStorage node = it.next();
|
while ( amt > 0 && it.hasNext() )
|
||||||
amt = node.injectAEPower( amt, mode );
|
|
||||||
|
|
||||||
if( amt > 0 && mode == Actionable.MODULATE )
|
|
||||||
{
|
{
|
||||||
it.remove();
|
final IAEPowerStorage node = it.next();
|
||||||
|
|
||||||
|
if ( requesterToRemove.contains( node )) {
|
||||||
|
it.remove();
|
||||||
|
requesterToRemove.remove( node );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
amt = node.injectAEPower( amt, mode );
|
||||||
|
|
||||||
|
if( amt > 0 && mode == Actionable.MODULATE )
|
||||||
|
{
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} finally
|
||||||
|
{
|
||||||
|
ongoingInjectOperation = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
final double overflow = Math.max( 0.0, amt );
|
final double overflow = Math.max( 0.0, amt );
|
||||||
@@ -505,9 +582,22 @@ public class EnergyGridCache implements IEnergyGrid
|
|||||||
this.globalMaxPower -= ps.getAEMaxPower();
|
this.globalMaxPower -= ps.getAEMaxPower();
|
||||||
this.globalAvailablePower -= ps.getAECurrentPower();
|
this.globalAvailablePower -= ps.getAECurrentPower();
|
||||||
}
|
}
|
||||||
|
if( !ongoingExtractOperation )
|
||||||
this.providers.remove( ps );
|
{
|
||||||
this.requesters.remove( ps );
|
removeProvider( ps );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.providerToRemove.add( ps );
|
||||||
|
}
|
||||||
|
if( !ongoingInjectOperation )
|
||||||
|
{
|
||||||
|
removeRequester( ps );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.requesterToRemove.add( ps );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -523,6 +613,31 @@ public class EnergyGridCache implements IEnergyGrid
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addRequester(IAEPowerStorage requester) {
|
||||||
|
Preconditions.checkState(!ongoingInjectOperation,
|
||||||
|
"Cannot modify energy requesters while energy is being injected.");
|
||||||
|
this.requesters.add(requester);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeRequester(IAEPowerStorage requester) {
|
||||||
|
Preconditions.checkState(!ongoingInjectOperation,
|
||||||
|
"Cannot modify energy requesters while energy is being injected.");
|
||||||
|
this.requesters.remove(requester);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addProvider(IAEPowerStorage provider) {
|
||||||
|
Preconditions.checkState(!ongoingExtractOperation,
|
||||||
|
"Cannot modify energy providers while energy is being extracted.");
|
||||||
|
this.providers.add(provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeProvider(IAEPowerStorage provider) {
|
||||||
|
Preconditions.checkState(!ongoingExtractOperation,
|
||||||
|
"Cannot modify energy providers while energy is being extracted.");
|
||||||
|
this.providers.remove(provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addNode( final IGridNode node, final IGridHost machine )
|
public void addNode( final IGridNode node, final IGridHost machine )
|
||||||
{
|
{
|
||||||
@@ -554,12 +669,26 @@ public class EnergyGridCache implements IEnergyGrid
|
|||||||
if( current > 0 && ps.getPowerFlow() != AccessRestriction.WRITE )
|
if( current > 0 && ps.getPowerFlow() != AccessRestriction.WRITE )
|
||||||
{
|
{
|
||||||
this.globalAvailablePower += current;
|
this.globalAvailablePower += current;
|
||||||
this.providers.add( ps );
|
if( !ongoingExtractOperation )
|
||||||
|
{
|
||||||
|
addProvider( ps );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.providersToAdd.add( ps );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( current < max && ps.getPowerFlow() != AccessRestriction.READ )
|
if( current < max && ps.getPowerFlow() != AccessRestriction.READ )
|
||||||
{
|
{
|
||||||
this.requesters.add( ps );
|
if( !ongoingInjectOperation )
|
||||||
|
{
|
||||||
|
addRequester( ps );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.requesterToAdd.add( ps );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -101,12 +101,12 @@ public class GridStorageCache implements IStorageGrid
|
|||||||
|
|
||||||
if( machine instanceof IStackWatcherHost )
|
if( machine instanceof IStackWatcherHost )
|
||||||
{
|
{
|
||||||
final IStackWatcher myWatcher = this.watchers.get( machine );
|
final IStackWatcher myWatcher = this.watchers.get( node );
|
||||||
|
|
||||||
if( myWatcher != null )
|
if( myWatcher != null )
|
||||||
{
|
{
|
||||||
myWatcher.reset();
|
myWatcher.reset();
|
||||||
this.watchers.remove( machine );
|
this.watchers.remove( node );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -314,7 +314,7 @@ public class PathGridCache implements IPathingGrid
|
|||||||
int depth = 0;
|
int depth = 0;
|
||||||
for( final IGridNode nodes : this.requireChannels )
|
for( final IGridNode nodes : this.requireChannels )
|
||||||
{
|
{
|
||||||
if( !this.semiOpen.contains( nodes ) )
|
if( !this.semiOpen.contains( (IPathItem) nodes ) )
|
||||||
{
|
{
|
||||||
final IGridBlock gb = nodes.getGridBlock();
|
final IGridBlock gb = nodes.getGridBlock();
|
||||||
final EnumSet<GridFlags> flags = gb.getFlags();
|
final EnumSet<GridFlags> flags = gb.getFlags();
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import java.util.*;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import net.minecraft.inventory.InventoryCrafting;
|
import net.minecraft.inventory.InventoryCrafting;
|
||||||
@@ -233,8 +234,9 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
|||||||
|
|
||||||
public IAEItemStack injectItems( final IAEItemStack input, final Actionable type, final IActionSource src )
|
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;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,7 +294,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
|||||||
{
|
{
|
||||||
is.decStackSize( what.getStackSize() );
|
is.decStackSize( what.getStackSize() );
|
||||||
|
|
||||||
this.updateElapsedTime( what );
|
this.updateRemainingItemCount( what );
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
this.postCraftingStatusChange( what.copy().setStackSize( -what.getStackSize() ) );
|
this.postCraftingStatusChange( what.copy().setStackSize( -what.getStackSize() ) );
|
||||||
|
|
||||||
@@ -431,6 +433,11 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
|||||||
AELog.crafting( LOG_MARK_AS_COMPLETE, logStack );
|
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.remainingItemCount = 0;
|
||||||
this.startItemCount = 0;
|
this.startItemCount = 0;
|
||||||
this.lastTime = 0;
|
this.lastTime = 0;
|
||||||
@@ -828,6 +835,7 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
|||||||
|
|
||||||
private void storeItems()
|
private void storeItems()
|
||||||
{
|
{
|
||||||
|
Preconditions.checkState(isComplete, "CPU should be complete to prevent re-insertion when dumping items");
|
||||||
final IGrid g = this.getGrid();
|
final IGrid g = this.getGrid();
|
||||||
|
|
||||||
if( g == null )
|
if( g == null )
|
||||||
@@ -838,23 +846,24 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
|||||||
final IStorageGrid sg = g.getCache( IStorageGrid.class );
|
final IStorageGrid sg = g.getCache( IStorageGrid.class );
|
||||||
final IMEInventory<IAEItemStack> ii = sg.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.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.setStackSize( remainder.getStackSize() );
|
||||||
is = ii.injectItems( is, Actionable.MODULATE, this.machineSrc );
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if( is != null )
|
|
||||||
{
|
{
|
||||||
this.inventory.injectItems( is, Actionable.MODULATE, this.machineSrc );
|
is.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( this.inventory.getItemList().isEmpty() )
|
if( itemList.isEmpty() )
|
||||||
{
|
{
|
||||||
this.inventory = new MECraftingInventory();
|
this.inventory = new MECraftingInventory();
|
||||||
}
|
}
|
||||||
@@ -939,14 +948,13 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
|||||||
@Override
|
@Override
|
||||||
public boolean isBusy()
|
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 )
|
this.updateElapsedTime();
|
||||||
{
|
|
||||||
i.remove();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return !this.tasks.isEmpty() || !this.waitingFor.isEmpty();
|
return !this.tasks.isEmpty() || !this.waitingFor.isEmpty();
|
||||||
@@ -1338,12 +1346,16 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
|||||||
this.remainingItemCount = itemCount;
|
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();
|
final long nextStartTime = System.nanoTime();
|
||||||
this.elapsedTime = this.getElapsedTime() + nextStartTime - this.lastTime;
|
this.elapsedTime = this.getElapsedTime() + nextStartTime - this.lastTime;
|
||||||
this.lastTime = nextStartTime;
|
this.lastTime = nextStartTime;
|
||||||
this.remainingItemCount = this.getRemainingItemCount() - is.getStackSize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getElapsedTime()
|
public long getElapsedTime()
|
||||||
|
|||||||
@@ -277,6 +277,7 @@ public class BasicCellInventory<T extends IAEStack<T>> extends AbstractCellInven
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.setStackSize( stackSize );
|
t.setStackSize( stackSize );
|
||||||
|
t.setCraftable( false );
|
||||||
|
|
||||||
if( stackSize > 0 )
|
if( stackSize > 0 )
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
package appeng.parts.automation;
|
package appeng.parts.automation;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import appeng.me.Grid;
|
import appeng.me.Grid;
|
||||||
@@ -27,7 +26,6 @@ import appeng.me.GridNode;
|
|||||||
import appeng.util.item.AEItemStack;
|
import appeng.util.item.AEItemStack;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2LongMap;
|
import it.unimi.dsi.fastutil.objects.Object2LongMap;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
|
||||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.InventoryCrafting;
|
import net.minecraft.inventory.InventoryCrafting;
|
||||||
@@ -128,8 +126,6 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
|
|||||||
static Object2LongMap<Grid> gridItemCount = new Object2LongOpenHashMap<>();
|
static Object2LongMap<Grid> gridItemCount = new Object2LongOpenHashMap<>();
|
||||||
static Object2ObjectOpenHashMap<Grid, Object2LongMap<AEItemStack>> fuzzyAEItemStackCount = new Object2ObjectOpenHashMap<>();
|
static Object2ObjectOpenHashMap<Grid, Object2LongMap<AEItemStack>> fuzzyAEItemStackCount = new Object2ObjectOpenHashMap<>();
|
||||||
static Object2ObjectOpenHashMap<Grid, Object2LongMap<AEItemStack>> preciseAEItemStackCount = new Object2ObjectOpenHashMap<>();
|
static Object2ObjectOpenHashMap<Grid, Object2LongMap<AEItemStack>> preciseAEItemStackCount = new Object2ObjectOpenHashMap<>();
|
||||||
static Object2ObjectMap<Grid,Iterable<IAEItemStack>> previousChange = new Object2ObjectOpenHashMap<>();
|
|
||||||
static Object2ObjectMap<Grid,IItemList<IAEItemStack>> cachedStorageList = new Object2ObjectOpenHashMap<>();
|
|
||||||
|
|
||||||
@Reflected
|
@Reflected
|
||||||
public PartLevelEmitter( final ItemStack is )
|
public PartLevelEmitter( final ItemStack is )
|
||||||
@@ -328,90 +324,54 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
|
|||||||
|
|
||||||
private void updateReportingValue( final IMEMonitor<IAEItemStack> monitor )
|
private void updateReportingValue( final IMEMonitor<IAEItemStack> monitor )
|
||||||
{
|
{
|
||||||
updateReportingValue( monitor, new ArrayList<>() );
|
updateReportingValue( monitor,null );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateReportingValue( final IMEMonitor<IAEItemStack> monitor, Iterable<IAEItemStack> change )
|
private void updateReportingValue( final IMEMonitor<IAEItemStack> monitor, Iterable<IAEItemStack> change )
|
||||||
{
|
{
|
||||||
final IAEItemStack myStack = this.config.getAEStackInSlot( 0 );
|
final IAEItemStack myStack = this.config.getAEStackInSlot( 0 );
|
||||||
|
|
||||||
GridNode node = (GridNode) ( this.getGridNode() );
|
GridNode node = (GridNode) (this.getGridNode());
|
||||||
|
|
||||||
if( node != null )
|
if( node != null )
|
||||||
{
|
{
|
||||||
|
|
||||||
final Grid g = node.getInternalGrid();
|
final Grid g = node.getInternalGrid();
|
||||||
|
|
||||||
IItemList<IAEItemStack> l;
|
|
||||||
boolean alreadyEvaluated = false;
|
|
||||||
|
|
||||||
if( previousChange.containsKey( g ) )
|
|
||||||
{
|
|
||||||
if( change.iterator().hasNext() && previousChange.get( g ).iterator().hasNext() )
|
|
||||||
{
|
|
||||||
IAEItemStack a = change.iterator().next();
|
|
||||||
IAEItemStack b = previousChange.get( g ).iterator().next();
|
|
||||||
if( a == b )
|
|
||||||
{
|
|
||||||
alreadyEvaluated = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
alreadyEvaluated = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( alreadyEvaluated )
|
|
||||||
{
|
|
||||||
l = cachedStorageList.get( g );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
l = monitor.getStorageList();
|
|
||||||
cachedStorageList.put( g, l );
|
|
||||||
if ( change.iterator().hasNext() )
|
|
||||||
{
|
|
||||||
previousChange.put( g, change );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
previousChange.put( g, new ArrayList<>() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( myStack == null )
|
if( myStack == null )
|
||||||
{
|
{
|
||||||
if( gridItemCount.containsKey( g ) )
|
if( change != null )
|
||||||
{
|
{
|
||||||
change.forEach( iaeItemStack -> lastReportedValue += iaeItemStack.getStackSize() );
|
if( gridItemCount.containsKey( g ) )
|
||||||
|
{
|
||||||
|
change.forEach( iaeItemStack -> lastReportedValue += iaeItemStack.getStackSize() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gridItemCount.computeIfAbsent( g, ( aLong ) -> {
|
gridItemCount.computeIfAbsent( g, ( aLong ) -> {
|
||||||
this.lastReportedValue = 0;
|
this.lastReportedValue = 0;
|
||||||
l.forEach( iaeItemStack -> lastReportedValue += iaeItemStack.getStackSize() );
|
monitor.getStorageList().forEach( iaeItemStack -> lastReportedValue += iaeItemStack.getStackSize() );
|
||||||
return ( lastReportedValue );
|
return ( lastReportedValue );
|
||||||
} );
|
} );
|
||||||
this.lastReportedValue = gridItemCount.get( g );
|
this.lastReportedValue = gridItemCount.get( g );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
else if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
||||||
{
|
{
|
||||||
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE );
|
final FuzzyMode fzMode = (FuzzyMode) this.getConfigManager().getSetting( Settings.FUZZY_MODE );
|
||||||
|
if( change != null )
|
||||||
if( fuzzyAEItemStackCount.containsKey( g ) )
|
|
||||||
{
|
{
|
||||||
change.forEach( iaeItemStack -> {
|
if( fuzzyAEItemStackCount.containsKey( g ) )
|
||||||
if( iaeItemStack.sameOre( myStack ) )
|
{
|
||||||
{
|
change.forEach( iaeItemStack -> {
|
||||||
lastReportedValue += iaeItemStack.getStackSize();
|
if( iaeItemStack.sameOre( myStack ) ) lastReportedValue += iaeItemStack.getStackSize();
|
||||||
}
|
} );
|
||||||
} );
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fuzzyAEItemStackCount.computeIfAbsent( g, ( grid -> new Object2LongOpenHashMap<>() ) );
|
fuzzyAEItemStackCount.computeIfAbsent( g, ( grid -> new Object2LongOpenHashMap<>() ) );
|
||||||
fuzzyAEItemStackCount.get( g ).computeIfAbsent( (AEItemStack) myStack, ( aLong -> {
|
fuzzyAEItemStackCount.get( g ).computeIfAbsent( (AEItemStack) myStack, ( aLong -> {
|
||||||
this.lastReportedValue = 0;
|
this.lastReportedValue = 0;
|
||||||
l.findFuzzy( myStack, fzMode ).forEach( iaeItemStack -> lastReportedValue += iaeItemStack.getStackSize() );
|
monitor.getStorageList().findFuzzy( myStack, fzMode ).forEach( iaeItemStack -> lastReportedValue += iaeItemStack.getStackSize() );
|
||||||
return ( lastReportedValue );
|
return ( lastReportedValue );
|
||||||
} ) );
|
} ) );
|
||||||
|
|
||||||
@@ -424,17 +384,19 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( preciseAEItemStackCount.containsKey( g ) )
|
if( change != null )
|
||||||
{
|
{
|
||||||
change.forEach( iaeItemStack -> {
|
if( preciseAEItemStackCount.containsKey( g ) )
|
||||||
if( iaeItemStack.isSameType( myStack ) ) lastReportedValue += iaeItemStack.getStackSize();
|
{
|
||||||
} );
|
change.forEach( iaeItemStack -> {
|
||||||
|
if( iaeItemStack.isSameType( myStack ) ) lastReportedValue += iaeItemStack.getStackSize();
|
||||||
|
} );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
preciseAEItemStackCount.computeIfAbsent( g, ( grid -> new Object2LongOpenHashMap<>() ) );
|
preciseAEItemStackCount.computeIfAbsent( g, ( grid -> new Object2LongOpenHashMap<>() ) );
|
||||||
preciseAEItemStackCount.get( g ).computeIfAbsent( (AEItemStack) myStack, ( aLong -> {
|
preciseAEItemStackCount.get( g ).computeIfAbsent( (AEItemStack) myStack, ( aLong -> {
|
||||||
this.lastReportedValue = 0;
|
this.lastReportedValue = 0;
|
||||||
IAEItemStack precise = l.findPrecise( myStack );
|
IAEItemStack precise = monitor.getStorageList().findPrecise( myStack );
|
||||||
if( precise != null ) lastReportedValue = precise.getStackSize();
|
if( precise != null ) lastReportedValue = precise.getStackSize();
|
||||||
return ( lastReportedValue );
|
return ( lastReportedValue );
|
||||||
} ) );
|
} ) );
|
||||||
|
|||||||
@@ -19,17 +19,10 @@
|
|||||||
package appeng.parts.misc;
|
package appeng.parts.misc;
|
||||||
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import appeng.api.config.Settings;
|
|
||||||
import appeng.api.config.StorageFilter;
|
|
||||||
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 appeng.api.AEApi;
|
import appeng.api.AEApi;
|
||||||
import appeng.api.config.Actionable;
|
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.security.IActionSource;
|
||||||
import appeng.api.networking.storage.IBaseMonitor;
|
import appeng.api.networking.storage.IBaseMonitor;
|
||||||
import appeng.api.networking.ticking.TickRateModulation;
|
import appeng.api.networking.ticking.TickRateModulation;
|
||||||
@@ -39,12 +32,24 @@ import appeng.api.storage.channels.IItemStorageChannel;
|
|||||||
import appeng.api.storage.data.IAEItemStack;
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
import appeng.api.storage.data.IItemList;
|
import appeng.api.storage.data.IItemList;
|
||||||
import appeng.core.AELog;
|
import appeng.core.AELog;
|
||||||
|
import appeng.me.GridAccessException;
|
||||||
import appeng.me.helpers.IGridProxyable;
|
import appeng.me.helpers.IGridProxyable;
|
||||||
import appeng.me.storage.ITickingMonitor;
|
import appeng.me.storage.ITickingMonitor;
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
|
import appeng.util.inv.ItemHandlerIterator;
|
||||||
|
import appeng.util.inv.ItemSlot;
|
||||||
import appeng.util.item.AEItemStack;
|
import appeng.util.item.AEItemStack;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.items.IItemHandler;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps an Item Handler in such a way that it can be used as an IMEInventory for items.
|
* Wraps an Item Handler in such a way that it can be used as an IMEInventory for items.
|
||||||
@@ -79,22 +84,15 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
|||||||
|
|
||||||
int slotCount = this.itemHandler.getSlots();
|
int slotCount = this.itemHandler.getSlots();
|
||||||
boolean simulate = ( type == Actionable.SIMULATE );
|
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.
|
// 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 );
|
remaining = this.itemHandler.insertItem( i, remaining, simulate );
|
||||||
int countPos = remaining.getCount();
|
|
||||||
if( remaining.isEmpty() )
|
if( remaining.isEmpty() )
|
||||||
{
|
{
|
||||||
injectedList.add( Pair.of( i, countPre ) );
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if( countPos < countPre )
|
|
||||||
{
|
|
||||||
injectedList.add( Pair.of( i, countPre - countPos ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this point, we still have some items left...
|
// At this point, we still have some items left...
|
||||||
@@ -106,28 +104,13 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
|||||||
|
|
||||||
if( type == Actionable.MODULATE )
|
if( type == Actionable.MODULATE )
|
||||||
{
|
{
|
||||||
if( this.cache.cachedAeStacks.length == 0 )
|
try
|
||||||
{
|
{
|
||||||
this.cache.update();
|
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
|
||||||
}
|
}
|
||||||
else
|
catch( GridAccessException ex )
|
||||||
{
|
{
|
||||||
for( Pair<Integer, Integer> pair : injectedList )
|
// meh
|
||||||
{
|
|
||||||
if( pair.getKey() >= this.cache.cachedAeStacks.length )
|
|
||||||
{
|
|
||||||
this.cache.update();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
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() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -145,10 +128,8 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
|||||||
ItemStack gathered = ItemStack.EMPTY;
|
ItemStack gathered = ItemStack.EMPTY;
|
||||||
|
|
||||||
final boolean simulate = ( mode == Actionable.SIMULATE );
|
final boolean simulate = ( mode == Actionable.SIMULATE );
|
||||||
List<Pair<Integer, Integer>> extractedList = new ArrayList<>();
|
|
||||||
|
|
||||||
|
for( int i = 0; i < this.itemHandler.getSlots(); i++ )
|
||||||
for ( int i = 0; i < this.itemHandler.getSlots(); i++ )
|
|
||||||
{
|
{
|
||||||
ItemStack stackInInventorySlot = this.itemHandler.getStackInSlot( i );
|
ItemStack stackInInventorySlot = this.itemHandler.getStackInSlot( i );
|
||||||
|
|
||||||
@@ -191,16 +172,10 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
|||||||
}
|
}
|
||||||
remainingCurrentSlot -= extracted.getCount();
|
remainingCurrentSlot -= extracted.getCount();
|
||||||
}
|
}
|
||||||
}
|
} while ( !extracted.isEmpty() && remainingCurrentSlot > 0 );
|
||||||
while ( !extracted.isEmpty() && remainingCurrentSlot > 0 );
|
|
||||||
|
|
||||||
remainingSize -= stackSizeCurrentSlot - remainingCurrentSlot;
|
remainingSize -= stackSizeCurrentSlot - remainingCurrentSlot;
|
||||||
|
|
||||||
if (!gathered.isEmpty())
|
|
||||||
{
|
|
||||||
extractedList.add( Pair.of( i, gathered.getCount() ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Done?
|
// Done?
|
||||||
if( remainingSize <= 0 )
|
if( remainingSize <= 0 )
|
||||||
{
|
{
|
||||||
@@ -212,23 +187,13 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
|||||||
{
|
{
|
||||||
if( mode == Actionable.MODULATE )
|
if( mode == Actionable.MODULATE )
|
||||||
{
|
{
|
||||||
if( this.cache.cachedAeStacks.length == 0 )
|
try
|
||||||
{
|
{
|
||||||
this.cache.update();
|
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
|
||||||
}
|
}
|
||||||
else
|
catch( GridAccessException ex )
|
||||||
{
|
{
|
||||||
for( Pair<Integer, Integer> pair : extractedList )
|
// meh
|
||||||
{
|
|
||||||
if( this.cache.cachedAeStacks[pair.getKey()] != null )
|
|
||||||
{
|
|
||||||
this.cache.cachedAeStacks[pair.getKey()].decStackSize( pair.getValue() );
|
|
||||||
if( this.cache.cachedAeStacks[pair.getKey()].getStackSize() == 0 )
|
|
||||||
{
|
|
||||||
this.cache.cachedAeStacks[pair.getKey()] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,7 +251,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
|||||||
private void postDifference( Iterable<IAEItemStack> a )
|
private void postDifference( Iterable<IAEItemStack> a )
|
||||||
{
|
{
|
||||||
final Iterator<Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object>> i = this.listeners.entrySet().iterator();
|
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 Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object> l = i.next();
|
||||||
final IMEMonitorHandlerReceiver<IAEItemStack> key = l.getKey();
|
final IMEMonitorHandlerReceiver<IAEItemStack> key = l.getKey();
|
||||||
@@ -301,9 +266,9 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class InventoryCache
|
private static class InventoryCache implements Iterable<ItemSlot>
|
||||||
{
|
{
|
||||||
private IAEItemStack[] cachedAeStacks = new IAEItemStack[0];
|
private IItemList<IAEItemStack> cachedAeStacks = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||||
private final IItemHandler itemHandler;
|
private final IItemHandler itemHandler;
|
||||||
private final StorageFilter mode;
|
private final StorageFilter mode;
|
||||||
|
|
||||||
@@ -315,106 +280,77 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
|
|||||||
|
|
||||||
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
|
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
|
||||||
{
|
{
|
||||||
Arrays.stream( this.cachedAeStacks ).forEach( out::add );
|
this.cachedAeStacks.forEach( out::add );
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private StorageFilter getMode()
|
||||||
|
{
|
||||||
|
return this.mode;
|
||||||
|
}
|
||||||
|
|
||||||
public List<IAEItemStack> update()
|
public List<IAEItemStack> update()
|
||||||
{
|
{
|
||||||
final List<IAEItemStack> changes = new ArrayList<>();
|
final List<IAEItemStack> changes = new ArrayList<>();
|
||||||
final int slots = this.itemHandler.getSlots();
|
|
||||||
|
|
||||||
// Make room for new slots
|
IItemList<IAEItemStack> storage = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||||
if( slots > this.cachedAeStacks.length )
|
|
||||||
|
for( final ItemSlot is : this )
|
||||||
{
|
{
|
||||||
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, slots );
|
final ItemStack stackInSlot = !is.isExtractable() && this.getMode() == StorageFilter.EXTRACTABLE_ONLY ? ItemStack.EMPTY : is.getItemStack();
|
||||||
|
if( !stackInSlot.isEmpty() )
|
||||||
|
{
|
||||||
|
storage.add( AEItemStack.fromItemStack( stackInSlot ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int slot = 0; slot < slots; slot++ )
|
Iterator<IAEItemStack> cachedAeStacksIterator = cachedAeStacks.iterator();
|
||||||
|
while ( cachedAeStacksIterator.hasNext() )
|
||||||
{
|
{
|
||||||
// Save the old stuff
|
IAEItemStack cachedStack = cachedAeStacksIterator.next();
|
||||||
final IAEItemStack oldAeIS = this.cachedAeStacks[slot];
|
IAEItemStack storedStack = storage.findPrecise( cachedStack );
|
||||||
ItemStack newIS = this.itemHandler.getStackInSlot( slot );
|
if( storedStack == null )
|
||||||
if( this.mode == StorageFilter.EXTRACTABLE_ONLY && !newIS.isEmpty() )
|
|
||||||
{
|
{
|
||||||
if( this.itemHandler.extractItem( slot, 1, true ).isEmpty() )
|
changes.add( cachedStack.setStackSize( -cachedStack.getStackSize() ) );
|
||||||
{
|
}
|
||||||
newIS = ItemStack.EMPTY;
|
else if( cachedStack.getStackSize() != storedStack.getStackSize() )
|
||||||
}
|
{
|
||||||
|
handleStackSizeChanged( cachedStack, storedStack, changes );
|
||||||
}
|
}
|
||||||
this.handlePossibleSlotChanges( slot, oldAeIS, newIS, changes );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle cases where the number of slots actually is lower now than before
|
for( IAEItemStack storedStack : storage )
|
||||||
if( slots < this.cachedAeStacks.length )
|
|
||||||
{
|
{
|
||||||
for( int slot = slots; slot < this.cachedAeStacks.length; slot++ )
|
if( cachedAeStacks.findPrecise( storedStack ) == null )
|
||||||
{
|
{
|
||||||
final IAEItemStack aeStack = this.cachedAeStacks[slot];
|
cachedAeStacks.add( storedStack );
|
||||||
|
changes.add( storedStack.copy() );
|
||||||
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 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return changes;
|
return changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handlePossibleSlotChanges( int slot, IAEItemStack oldAeIS, ItemStack newIS, List<IAEItemStack> changes )
|
private void handleStackSizeChanged( IAEItemStack cachedStack, IAEItemStack storedStack, List<IAEItemStack> changes )
|
||||||
{
|
|
||||||
if( oldAeIS != null && oldAeIS.isSameType( newIS ) )
|
|
||||||
{
|
|
||||||
this.handleStackSizeChanged( slot, oldAeIS, newIS, changes );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.handleItemChanged( slot, oldAeIS, newIS, changes );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleStackSizeChanged( int slot, IAEItemStack oldAeIS, ItemStack newIS, List<IAEItemStack> changes )
|
|
||||||
{
|
{
|
||||||
// Still the same item, but amount might have changed
|
// Still the same item, but amount might have changed
|
||||||
final long diff = newIS.getCount() - oldAeIS.getStackSize();
|
final long diff = storedStack.getStackSize() - cachedStack.getStackSize();
|
||||||
|
|
||||||
if( diff != 0 )
|
if( diff != 0 )
|
||||||
{
|
{
|
||||||
final IAEItemStack stack = oldAeIS.copy();
|
cachedStack.setStackSize( storedStack.getStackSize() );
|
||||||
stack.setStackSize( newIS.getCount() );
|
|
||||||
|
|
||||||
this.cachedAeStacks[slot] = stack;
|
final IAEItemStack diffStack = cachedStack.copy();
|
||||||
|
diffStack.setStackSize( diff );
|
||||||
final IAEItemStack a = stack.copy();
|
changes.add( diffStack );
|
||||||
a.setStackSize( diff );
|
|
||||||
changes.add( a );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleItemChanged( int slot, IAEItemStack oldAeIS, ItemStack newIS, List<IAEItemStack> changes )
|
@Override
|
||||||
|
public Iterator<ItemSlot> iterator()
|
||||||
{
|
{
|
||||||
// Completely different item
|
return new ItemHandlerIterator( this.itemHandler );
|
||||||
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.copy() );
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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,16 +1,5 @@
|
|||||||
package appeng.parts.misc;
|
package appeng.parts.misc;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import appeng.api.storage.IStorageChannel;
|
|
||||||
|
|
||||||
import appeng.core.AELog;
|
|
||||||
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 appeng.api.AEApi;
|
import appeng.api.AEApi;
|
||||||
import appeng.api.config.Actionable;
|
import appeng.api.config.Actionable;
|
||||||
import appeng.api.networking.security.IActionSource;
|
import appeng.api.networking.security.IActionSource;
|
||||||
@@ -18,15 +7,24 @@ import appeng.api.networking.storage.IBaseMonitor;
|
|||||||
import appeng.api.networking.ticking.TickRateModulation;
|
import appeng.api.networking.ticking.TickRateModulation;
|
||||||
import appeng.api.storage.IMEInventory;
|
import appeng.api.storage.IMEInventory;
|
||||||
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
||||||
|
import appeng.api.storage.IStorageChannel;
|
||||||
import appeng.api.storage.channels.IItemStorageChannel;
|
import appeng.api.storage.channels.IItemStorageChannel;
|
||||||
import appeng.api.storage.data.IAEItemStack;
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
import appeng.api.storage.data.IItemList;
|
import appeng.api.storage.data.IItemList;
|
||||||
|
import appeng.core.AELog;
|
||||||
import appeng.me.GridAccessException;
|
import appeng.me.GridAccessException;
|
||||||
import appeng.me.helpers.IGridProxyable;
|
import appeng.me.helpers.IGridProxyable;
|
||||||
import appeng.me.storage.ITickingMonitor;
|
import appeng.me.storage.ITickingMonitor;
|
||||||
import appeng.util.item.AEItemStack;
|
import appeng.util.item.AEItemStack;
|
||||||
|
import com.jaquadro.minecraft.storagedrawers.api.capabilities.IItemRepository;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wraps an Item Repository in such a way that it can be used as an IMEInventory for items.
|
* Wraps an Item Repository in such a way that it can be used as an IMEInventory for items.
|
||||||
@@ -86,7 +84,7 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
|||||||
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, IActionSource src )
|
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, IActionSource src )
|
||||||
{
|
{
|
||||||
ItemStack requestedItemStack = request.getDefinition();
|
ItemStack requestedItemStack = request.getDefinition();
|
||||||
int remainingSize = (int) Math.min( Integer.MAX_VALUE, request.getStackSize());
|
int remainingSize = (int) Math.min( Integer.MAX_VALUE, request.getStackSize() );
|
||||||
|
|
||||||
final boolean simulate = ( mode == Actionable.SIMULATE );
|
final boolean simulate = ( mode == Actionable.SIMULATE );
|
||||||
|
|
||||||
@@ -146,7 +144,7 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
|||||||
private void postDifference( Iterable<IAEItemStack> a )
|
private void postDifference( Iterable<IAEItemStack> a )
|
||||||
{
|
{
|
||||||
final Iterator<Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object>> i = this.listeners.entrySet().iterator();
|
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 Map.Entry<IMEMonitorHandlerReceiver<IAEItemStack>, Object> l = i.next();
|
||||||
final IMEMonitorHandlerReceiver<IAEItemStack> key = l.getKey();
|
final IMEMonitorHandlerReceiver<IAEItemStack> key = l.getKey();
|
||||||
@@ -186,7 +184,7 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
|||||||
|
|
||||||
private static class InventoryCache
|
private static class InventoryCache
|
||||||
{
|
{
|
||||||
private IAEItemStack[] cachedAeStacks = new IAEItemStack[0];
|
private IItemList<IAEItemStack> cachedAeStacks = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||||
private final IItemRepository iItemRepository;
|
private final IItemRepository iItemRepository;
|
||||||
|
|
||||||
public InventoryCache( IItemRepository iItemRepository )
|
public InventoryCache( IItemRepository iItemRepository )
|
||||||
@@ -196,7 +194,7 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
|||||||
|
|
||||||
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
|
public IItemList<IAEItemStack> getAvailableItems( IItemList<IAEItemStack> out )
|
||||||
{
|
{
|
||||||
Arrays.stream( this.cachedAeStacks ).forEach( out::add );
|
this.cachedAeStacks.forEach( out::add );
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,94 +202,51 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
|
|||||||
{
|
{
|
||||||
final List<IAEItemStack> changes = new ArrayList<>();
|
final List<IAEItemStack> changes = new ArrayList<>();
|
||||||
|
|
||||||
List<IAEItemStack> out = this.iItemRepository.getAllItems().stream().map( s -> AEItemStack.fromItemStack( s.itemPrototype ).setStackSize( s.count ) ).collect(Collectors.toList() );
|
IItemList<IAEItemStack> storage = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||||
|
this.iItemRepository.getAllItems().stream().map( s -> AEItemStack.fromItemStack( s.itemPrototype ).setStackSize( s.count ) ).forEach( storage::add );
|
||||||
|
|
||||||
final int size = out.size();
|
Iterator<IAEItemStack> cachedAeStacksIterator = cachedAeStacks.iterator();
|
||||||
|
while ( cachedAeStacksIterator.hasNext() )
|
||||||
// Make room for new slots
|
|
||||||
if( size > this.cachedAeStacks.length )
|
|
||||||
{
|
{
|
||||||
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, size );
|
IAEItemStack cachedStack = cachedAeStacksIterator.next();
|
||||||
}
|
IAEItemStack storedStack = storage.findPrecise( cachedStack );
|
||||||
|
if( storedStack == null )
|
||||||
for( int x = 0; x < size; x++ )
|
|
||||||
{
|
|
||||||
// Save the old stuff
|
|
||||||
final IAEItemStack oldAeIS = this.cachedAeStacks[x];
|
|
||||||
final IAEItemStack newIS = out.get( x );
|
|
||||||
|
|
||||||
this.handlePossibleSlotChanges( x, oldAeIS, newIS, changes );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle cases where the number of slots actually is lower now than before
|
|
||||||
if( size < this.cachedAeStacks.length )
|
|
||||||
{
|
|
||||||
for( int x = 0; x < this.cachedAeStacks.length; x++ )
|
|
||||||
{
|
{
|
||||||
final IAEItemStack aeStack = this.cachedAeStacks[x];
|
changes.add( cachedStack.setStackSize( -cachedStack.getStackSize() ) );
|
||||||
|
cachedAeStacksIterator.remove();
|
||||||
if( aeStack != null )
|
|
||||||
{
|
|
||||||
final IAEItemStack a = aeStack.copy();
|
|
||||||
a.setStackSize( -a.getStackSize() );
|
|
||||||
changes.add( a );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else if( cachedStack.getStackSize() != storedStack.getStackSize() )
|
||||||
|
{
|
||||||
|
handleStackSizeChanged( cachedStack, storedStack, changes );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Reduce the cache size
|
for( IAEItemStack storedStack : storage )
|
||||||
this.cachedAeStacks = Arrays.copyOf( this.cachedAeStacks, size );
|
{
|
||||||
|
if( cachedAeStacks.findPrecise( storedStack ) == null )
|
||||||
|
{
|
||||||
|
cachedAeStacks.add( storedStack );
|
||||||
|
changes.add( storedStack.copy() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return changes;
|
return changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handlePossibleSlotChanges( int slot, IAEItemStack oldAeIS, IAEItemStack newIS, List<IAEItemStack> changes )
|
private void handleStackSizeChanged( IAEItemStack cachedStack, IAEItemStack storedStack, 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
|
// Still the same item, but amount might have changed
|
||||||
final long diff = newIS.getStackSize() - oldAeIS.getStackSize();
|
final long diff = storedStack.getStackSize() - cachedStack.getStackSize();
|
||||||
|
|
||||||
if( diff != 0 )
|
if( diff != 0 )
|
||||||
{
|
{
|
||||||
final IAEItemStack stack = oldAeIS.copy();
|
cachedStack.setStackSize( storedStack.getStackSize() );
|
||||||
stack.setStackSize( newIS.getStackSize() );
|
|
||||||
|
|
||||||
this.cachedAeStacks[slot] = stack;
|
final IAEItemStack diffStack = cachedStack.copy();
|
||||||
|
diffStack.setStackSize( diff );
|
||||||
final IAEItemStack a = stack.copy();
|
changes.add( diffStack );
|
||||||
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.copy() );
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,12 @@
|
|||||||
package appeng.parts.p2p;
|
package appeng.parts.p2p;
|
||||||
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import appeng.me.cache.helpers.TunnelCollection;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
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 static final IEnergyStorage NULL_ENERGY_STORAGE = new NullEnergyStorage();
|
||||||
private final IEnergyStorage inputHandler = new InputEnergyStorage();
|
private final IEnergyStorage inputHandler = new InputEnergyStorage();
|
||||||
private final IEnergyStorage outputHandler = new OutputEnergyStorage();
|
private final IEnergyStorage outputHandler = new OutputEnergyStorage();
|
||||||
|
private final Queue<PartP2PFEPower> outputs = new ArrayDeque<>();
|
||||||
|
|
||||||
public PartP2PFEPower( ItemStack is )
|
public PartP2PFEPower( ItemStack is )
|
||||||
{
|
{
|
||||||
@@ -108,6 +110,8 @@ public class PartP2PFEPower extends PartP2PTunnel<PartP2PFEPower>
|
|||||||
|
|
||||||
private class InputEnergyStorage implements IEnergyStorage
|
private class InputEnergyStorage implements IEnergyStorage
|
||||||
{
|
{
|
||||||
|
private boolean iteratingOutputs;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int extractEnergy( int maxExtract, boolean simulate )
|
public int extractEnergy( int maxExtract, boolean simulate )
|
||||||
{
|
{
|
||||||
@@ -131,8 +135,14 @@ public class PartP2PFEPower extends PartP2PTunnel<PartP2PFEPower>
|
|||||||
final int amountPerOutput = maxReceive / outputTunnels;
|
final int amountPerOutput = maxReceive / outputTunnels;
|
||||||
int overflow = amountPerOutput == 0 ? maxReceive : maxReceive % amountPerOutput;
|
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 IEnergyStorage output = target.getAttachedEnergyStorage();
|
||||||
final int toSend = amountPerOutput + overflow;
|
final int toSend = amountPerOutput + overflow;
|
||||||
final int received = output.receiveEnergy( toSend, simulate );
|
final int received = output.receiveEnergy( toSend, simulate );
|
||||||
|
|||||||
@@ -425,6 +425,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
|||||||
if( extracted != null )
|
if( extracted != null )
|
||||||
{
|
{
|
||||||
possible = extracted.getStackSize();
|
possible = extracted.getStackSize();
|
||||||
|
extracted.setCraftable( false );
|
||||||
final IAEStack failed = Platform.poweredInsert( energy, destination, extracted, this.mySrc );
|
final IAEStack failed = Platform.poweredInsert( energy, destination, extracted, this.mySrc );
|
||||||
|
|
||||||
if( failed != null )
|
if( failed != null )
|
||||||
|
|||||||
@@ -56,6 +56,6 @@ public class ReadOnlyCollection<T> implements IReadOnlyCollection<T>
|
|||||||
@Override
|
@Override
|
||||||
public boolean contains( final Object node )
|
public boolean contains( final Object node )
|
||||||
{
|
{
|
||||||
return this.c.contains( node );
|
return this.c.contains( (T) node );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Applied Energistics 2.
|
* 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
|
* 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
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
package appeng.util.item;
|
package appeng.util.item;
|
||||||
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -27,347 +26,291 @@ import javax.annotation.Nonnull;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
|
|
||||||
import appeng.api.AEApi;
|
|
||||||
import appeng.api.config.FuzzyMode;
|
import appeng.api.config.FuzzyMode;
|
||||||
import appeng.api.storage.IStorageChannel;
|
import appeng.api.storage.IStorageChannel;
|
||||||
import appeng.api.storage.channels.IItemStorageChannel;
|
import appeng.api.storage.channels.IItemStorageChannel;
|
||||||
import appeng.api.storage.data.IAEItemStack;
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
|
import appeng.core.Api;
|
||||||
import appeng.util.Platform;
|
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 final AESharedItemStack sharedStack;
|
||||||
{
|
private Optional<OreReference> oreReference;
|
||||||
private AESharedItemStack sharedStack;
|
|
||||||
private Optional<OreReference> oreReference;
|
|
||||||
|
|
||||||
@SideOnly( Side.CLIENT )
|
@SideOnly(Side.CLIENT)
|
||||||
private String displayName;
|
private String displayName;
|
||||||
@SideOnly( Side.CLIENT )
|
@SideOnly(Side.CLIENT)
|
||||||
private List<String> tooltip;
|
private List<String> tooltip;
|
||||||
@SideOnly( Side.CLIENT )
|
|
||||||
private ResourceLocation uniqueID;
|
|
||||||
|
|
||||||
private AEItemStack( final AEItemStack is )
|
private AEItemStack(final AEItemStack is) {
|
||||||
{
|
this.setStackSize(is.getStackSize());
|
||||||
this.setStackSize( is.getStackSize() );
|
this.setCraftable(is.isCraftable());
|
||||||
this.setCraftable( is.isCraftable() );
|
this.setCountRequestable(is.getCountRequestable());
|
||||||
this.setCountRequestable( is.getCountRequestable() );
|
this.sharedStack = is.sharedStack;
|
||||||
this.sharedStack = is.sharedStack;
|
this.oreReference = is.oreReference;
|
||||||
this.oreReference = is.oreReference;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private AEItemStack( final AESharedItemStack is, long size )
|
private AEItemStack(final AESharedItemStack is, long size) {
|
||||||
{
|
this.sharedStack = is;
|
||||||
this.sharedStack = is;
|
this.setStackSize(size);
|
||||||
this.setStackSize( size );
|
this.setCraftable(false);
|
||||||
this.setCraftable( false );
|
this.setCountRequestable(0);
|
||||||
this.setCountRequestable( 0 );
|
this.oreReference = OreHelper.INSTANCE.getOre( is.getDefinition() );
|
||||||
this.oreReference = OreHelper.INSTANCE.getOre( is.getDefinition() );
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static AEItemStack fromItemStack( @Nonnull final ItemStack stack )
|
public static AEItemStack fromItemStack(@Nonnull final ItemStack stack) {
|
||||||
{
|
if (stack.isEmpty()) {
|
||||||
if( stack.isEmpty() )
|
return null;
|
||||||
{
|
}
|
||||||
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 )
|
public static IAEItemStack fromNBT(final NBTTagCompound i) {
|
||||||
{
|
if (i == null) {
|
||||||
if( i == null )
|
return null;
|
||||||
{
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final ItemStack itemstack = new ItemStack( i );
|
final ItemStack itemstack = new ItemStack(i);
|
||||||
if( itemstack.isEmpty() )
|
final AEItemStack item = AEItemStack.fromItemStack(itemstack);
|
||||||
{
|
if (item == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final AEItemStack item = AEItemStack.fromItemStack( itemstack );
|
item.setStackSize(i.getLong(NBT_STACKSIZE));
|
||||||
item.setStackSize( i.getLong( "Cnt" ) );
|
item.setCountRequestable(i.getLong(NBT_REQUESTABLE));
|
||||||
item.setCountRequestable( i.getLong( "Req" ) );
|
item.setCraftable(i.getBoolean(NBT_CRAFTABLE));
|
||||||
item.setCraftable( i.getBoolean( "Craft" ) );
|
return item;
|
||||||
return item;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToNBT( final NBTTagCompound i )
|
public void writeToNBT(final NBTTagCompound i) {
|
||||||
{
|
final NBTTagCompound itemStack = new NBTTagCompound();
|
||||||
this.getDefinition().writeToNBT( i );
|
this.getDefinition().writeToNBT(itemStack);
|
||||||
i.setLong( "Cnt", this.getStackSize() );
|
|
||||||
i.setLong( "Req", this.getCountRequestable() );
|
|
||||||
i.setBoolean( "Craft", this.isCraftable() );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AEItemStack fromPacket( final ByteBuf data )
|
i.setLong(NBT_STACKSIZE, this.getStackSize());
|
||||||
{
|
i.setLong(NBT_REQUESTABLE, this.getCountRequestable());
|
||||||
final byte mask = data.readByte();
|
i.setBoolean(NBT_CRAFTABLE, this.isCraftable());
|
||||||
final byte stackType = (byte) ( ( mask & 0x0C ) >> 2 );
|
}
|
||||||
final byte countReqType = (byte) ( ( mask & 0x30 ) >> 4 );
|
|
||||||
final boolean isCraftable = ( mask & 0x40 ) > 0;
|
|
||||||
|
|
||||||
final ItemStack itemstack = new ItemStack( ByteBufUtils.readTag( data ) );
|
public static AEItemStack fromPacket( final ByteBuf data )
|
||||||
final long stackSize = getPacketValue( stackType, data );
|
{
|
||||||
final long countRequestable = getPacketValue( countReqType, data );
|
final byte mask = data.readByte();
|
||||||
|
final byte stackType = (byte) ( ( mask & 0x0C ) >> 2 );
|
||||||
|
final byte countReqType = (byte) ( ( mask & 0x30 ) >> 4 );
|
||||||
|
final boolean isCraftable = ( mask & 0x40 ) > 0;
|
||||||
|
|
||||||
if( itemstack.isEmpty() )
|
final ItemStack itemstack = new ItemStack( ByteBufUtils.readTag( data ) );
|
||||||
{
|
final long stackSize = getPacketValue( stackType, data );
|
||||||
return null;
|
final long countRequestable = getPacketValue( countReqType, data );
|
||||||
}
|
|
||||||
|
|
||||||
final AEItemStack item = new AEItemStack( AEItemStackRegistry.getRegisteredStack( itemstack ), stackSize );
|
if( itemstack.isEmpty() )
|
||||||
item.setCountRequestable( countRequestable );
|
{
|
||||||
item.setCraftable( isCraftable );
|
return null;
|
||||||
return item;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
final AEItemStack item = new AEItemStack( AEItemStackRegistry.getRegisteredStack( itemstack ), stackSize );
|
||||||
public void writeToPacket( final ByteBuf i )
|
item.setCountRequestable( countRequestable );
|
||||||
{
|
item.setCraftable( isCraftable );
|
||||||
final byte mask = (byte) ( ( this.getType( this.getStackSize() ) << 2 ) | ( this
|
return item;
|
||||||
.getType( this.getCountRequestable() ) << 4 ) | ( (byte) ( this.isCraftable() ? 1 : 0 ) << 6 ) | ( this.hasTagCompound() ? 1 : 0 ) << 7 );
|
}
|
||||||
|
|
||||||
i.writeByte( mask );
|
@Override
|
||||||
ByteBufUtils.writeTag( i, this.getDefinition().serializeNBT() );
|
public void writeToPacket( final ByteBuf i )
|
||||||
this.putPacketValue( i, this.getStackSize() );
|
{
|
||||||
this.putPacketValue( i, this.getCountRequestable() );
|
final byte mask = (byte) ( ( this.getType( this.getStackSize() ) << 2 ) | ( this
|
||||||
}
|
.getType( this.getCountRequestable() ) << 4 ) | ( (byte) ( this.isCraftable() ? 1 : 0 ) << 6 ) | ( this.hasTagCompound() ? 1 : 0 ) << 7 );
|
||||||
|
|
||||||
@Override
|
i.writeByte( mask );
|
||||||
public void add( final IAEItemStack option )
|
ByteBufUtils.writeTag( i, this.getDefinition().serializeNBT() );
|
||||||
{
|
this.putPacketValue( i, this.getStackSize() );
|
||||||
if( option == null )
|
this.putPacketValue( i, this.getCountRequestable() );
|
||||||
{
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.incStackSize( option.getStackSize() );
|
@Override
|
||||||
this.setCountRequestable( this.getCountRequestable() + option.getCountRequestable() );
|
public void add(final IAEItemStack option) {
|
||||||
this.setCraftable( this.isCraftable() || option.isCraftable() );
|
if (option == null) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
this.incStackSize(option.getStackSize());
|
||||||
public boolean fuzzyComparison( final IAEItemStack other, final FuzzyMode mode )
|
this.setCountRequestable(this.getCountRequestable() + option.getCountRequestable());
|
||||||
{
|
this.setCraftable(this.isCraftable() || option.isCraftable());
|
||||||
if( mode == FuzzyMode.IGNORE_ALL && OreHelper.INSTANCE.sameOre( this, other ) )
|
}
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
final ItemStack itemStack = this.getDefinition();
|
@Override
|
||||||
final ItemStack otherStack = other.getDefinition();
|
public boolean fuzzyComparison(final IAEItemStack other, final FuzzyMode mode) {
|
||||||
|
final ItemStack itemStack = this.getDefinition();
|
||||||
|
final ItemStack otherStack = other.getDefinition();
|
||||||
|
|
||||||
return this.fuzzyItemStackComparison( itemStack, otherStack, mode );
|
return this.fuzzyItemStackComparison(itemStack, otherStack, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IAEItemStack copy()
|
public IAEItemStack copy() {
|
||||||
{
|
return new AEItemStack(this);
|
||||||
return new AEItemStack( this );
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isItem()
|
public boolean isItem()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isFluid()
|
public boolean isFluid()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IStorageChannel<IAEItemStack> getChannel()
|
public IStorageChannel<IAEItemStack> getChannel() {
|
||||||
{
|
return Api.INSTANCE.storage().getStorageChannel(IItemStorageChannel.class);
|
||||||
return AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class );
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack createItemStack()
|
public ItemStack createItemStack() {
|
||||||
{
|
return ItemHandlerHelper.copyStackWithSize(this.getDefinition(),
|
||||||
return ItemHandlerHelper.copyStackWithSize( this.getDefinition(), (int) Math.min( Integer.MAX_VALUE, this.getStackSize() ) );
|
(int) Math.min(Integer.MAX_VALUE, this.getStackSize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Item getItem()
|
public Item getItem() {
|
||||||
{
|
return this.getDefinition().getItem();
|
||||||
return this.getDefinition().getItem();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemDamage()
|
public int getItemDamage() {
|
||||||
{
|
return this.sharedStack.getItemDamage();
|
||||||
return this.sharedStack.getItemDamage();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean sameOre( final IAEItemStack is )
|
public boolean sameOre( final IAEItemStack is )
|
||||||
{
|
{
|
||||||
return OreHelper.INSTANCE.sameOre( this, is );
|
return OreHelper.INSTANCE.sameOre( this, is );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSameType( final IAEItemStack otherStack )
|
public boolean isSameType(final IAEItemStack otherStack) {
|
||||||
{
|
if (otherStack == null) {
|
||||||
if( otherStack == null )
|
return false;
|
||||||
{
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Objects.equals( this.sharedStack, ( (AEItemStack) otherStack ).sharedStack );
|
return Objects.equals(this.sharedStack, ((AEItemStack) otherStack).sharedStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSameType( final ItemStack otherStack )
|
public boolean isSameType(final ItemStack otherStack) {
|
||||||
{
|
if (otherStack.isEmpty()) {
|
||||||
if( otherStack.isEmpty() )
|
return false;
|
||||||
{
|
}
|
||||||
return false;
|
int oldSize = otherStack.getCount();
|
||||||
}
|
|
||||||
int oldSize = otherStack.getCount();
|
|
||||||
|
|
||||||
otherStack.setCount( 1 );
|
otherStack.setCount(1);
|
||||||
boolean ret = ItemStack.areItemStacksEqual( this.getDefinition(), otherStack );
|
boolean ret = ItemStack.areItemStacksEqual(this.getDefinition(), otherStack);
|
||||||
otherStack.setCount( oldSize );
|
otherStack.setCount(oldSize);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode() {
|
||||||
{
|
return this.sharedStack.hashCode();
|
||||||
return this.sharedStack.hashCode();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals( final Object ia )
|
public boolean equals(final Object ia) {
|
||||||
{
|
if (ia instanceof AEItemStack) {
|
||||||
if( ia instanceof AEItemStack )
|
return this.isSameType((AEItemStack) ia);
|
||||||
{
|
} else if (ia instanceof ItemStack) {
|
||||||
return this.isSameType( (AEItemStack) ia );
|
// this actually breaks the equals contract (being equals to unrelated classes)
|
||||||
}
|
return equals((ItemStack) ia);
|
||||||
else if( ia instanceof ItemStack )
|
}
|
||||||
{
|
return false;
|
||||||
return this.isSameType( (ItemStack) ia );
|
}
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public boolean equals(final ItemStack is) {
|
||||||
{
|
return this.isSameType(is);
|
||||||
return this.getStackSize() + "x" + this.getDefinition().getItem().getUnlocalizedName() + "@" + this.getDefinition().getItemDamage();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@SideOnly( Side.CLIENT )
|
@Override
|
||||||
public List<String> getToolTip()
|
public String toString() {
|
||||||
{
|
return this.getStackSize() + "x" + this.getDefinition().getItem().getRegistryName();
|
||||||
if( this.tooltip == null )
|
}
|
||||||
{
|
|
||||||
this.tooltip = Platform.getTooltip( this.asItemStackRepresentation() );
|
|
||||||
}
|
|
||||||
return this.tooltip;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SideOnly( Side.CLIENT )
|
@SideOnly(Side.CLIENT)
|
||||||
public String getDisplayName()
|
public List<String> getToolTip() {
|
||||||
{
|
if (this.tooltip == null) {
|
||||||
if( this.displayName == null )
|
this.tooltip = Platform.getTooltip(this.asItemStackRepresentation());
|
||||||
{
|
}
|
||||||
this.displayName = Platform.getItemDisplayName( this.asItemStackRepresentation() );
|
return this.tooltip;
|
||||||
}
|
}
|
||||||
return this.displayName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SideOnly( Side.CLIENT )
|
@SideOnly(Side.CLIENT)
|
||||||
public String getModID()
|
public String getDisplayName() {
|
||||||
{
|
if (this.displayName == null) {
|
||||||
if( this.uniqueID == null )
|
this.displayName = Platform.getItemDisplayName(this.asItemStackRepresentation());
|
||||||
{
|
}
|
||||||
this.uniqueID = Item.REGISTRY.getNameForObject( this.getDefinition().getItem() );
|
return this.displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( this.uniqueID == null )
|
@SideOnly(Side.CLIENT)
|
||||||
{
|
public String getModID() {
|
||||||
return "** Null";
|
return this.getDefinition().getItem().getRegistryName().getResourceDomain();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.uniqueID.getResourceDomain() == null ? "** Null" : this.uniqueID.getResourceDomain();
|
public Optional<OreReference> getOre()
|
||||||
}
|
{
|
||||||
|
return this.oreReference;
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<OreReference> getOre()
|
@Override
|
||||||
{
|
public boolean hasTagCompound() {
|
||||||
return this.oreReference;
|
return this.getDefinition().hasTagCompound();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasTagCompound()
|
public ItemStack asItemStackRepresentation() {
|
||||||
{
|
return this.getDefinition().copy();
|
||||||
return this.getDefinition().hasTagCompound();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack asItemStackRepresentation()
|
public ItemStack getDefinition() {
|
||||||
{
|
return this.sharedStack.getDefinition();
|
||||||
return this.getDefinition().copy();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
AESharedItemStack getSharedStack() {
|
||||||
public ItemStack getDefinition()
|
return this.sharedStack;
|
||||||
{
|
}
|
||||||
return this.sharedStack.getDefinition();
|
|
||||||
}
|
|
||||||
|
|
||||||
AESharedItemStack getSharedStack()
|
private boolean fuzzyItemStackComparison(ItemStack a, ItemStack b, FuzzyMode mode) {
|
||||||
{
|
if (a.getItem() == b.getItem() && a.getItem().isDamageable()) {
|
||||||
return this.sharedStack;
|
if (mode == FuzzyMode.IGNORE_ALL) {
|
||||||
}
|
return true;
|
||||||
|
} else if (mode == FuzzyMode.PERCENT_99) {
|
||||||
|
return a.getItemDamage() > 1 == b.getItemDamage() > 1;
|
||||||
|
} else {
|
||||||
|
final float percentDamageOfA = (float) a.getItemDamage() / a.getMaxDamage();
|
||||||
|
final float percentDamageOfB = (float) b.getItemDamage() / b.getMaxDamage();
|
||||||
|
|
||||||
private boolean fuzzyItemStackComparison( ItemStack a, ItemStack b, FuzzyMode mode )
|
return percentDamageOfA > mode.breakPoint == percentDamageOfB > mode.breakPoint;
|
||||||
{
|
}
|
||||||
if( a.getItem() == b.getItem() )
|
}
|
||||||
{
|
|
||||||
if( a.getItem().isDamageable() )
|
|
||||||
{
|
|
||||||
if( mode == FuzzyMode.IGNORE_ALL )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if( mode == FuzzyMode.PERCENT_99 )
|
|
||||||
{
|
|
||||||
return ( a.getItemDamage() > 1 ) == ( b.getItemDamage() > 1 );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
final float percentDamageOfA = (float) a.getItemDamage() / (float) a.getMaxDamage();
|
|
||||||
final float percentDamageOfB = (float) b.getItemDamage() / (float) b.getMaxDamage();
|
|
||||||
|
|
||||||
return ( percentDamageOfA > mode.breakPoint ) == ( percentDamageOfB > mode.breakPoint );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return a.getMetadata() == b.getMetadata();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
package appeng.util.item;
|
package appeng.util.item;
|
||||||
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
@@ -31,56 +30,34 @@ import javax.annotation.Nonnull;
|
|||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
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
|
static synchronized AESharedItemStack getRegisteredStack(final @Nonnull ItemStack itemStack) {
|
||||||
{
|
if (itemStack.isEmpty()) {
|
||||||
private static final WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> SERVER_REGISTRY = new WeakHashMap<>();
|
throw new IllegalArgumentException("stack cannot be empty");
|
||||||
private static final WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> CLIENT_REGISTRY = new WeakHashMap<>();
|
}
|
||||||
|
|
||||||
private AEItemStackRegistry()
|
int oldStackSize = itemStack.getCount();
|
||||||
{
|
itemStack.setCount(1);
|
||||||
}
|
|
||||||
|
|
||||||
private static WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> registry()
|
AESharedItemStack search = new AESharedItemStack(itemStack);
|
||||||
{
|
WeakReference<AESharedItemStack> weak = REGISTRY.get(search);
|
||||||
if( Platform.isClient() )
|
AESharedItemStack ret = null;
|
||||||
{
|
|
||||||
return CLIENT_REGISTRY;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return SERVER_REGISTRY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static synchronized AESharedItemStack getRegisteredStack( final @Nonnull ItemStack itemStack )
|
if (weak != null) {
|
||||||
{
|
ret = weak.get();
|
||||||
if( itemStack.isEmpty() )
|
}
|
||||||
{
|
|
||||||
throw new IllegalArgumentException( "stack cannot be empty" );
|
|
||||||
}
|
|
||||||
|
|
||||||
int oldStackSize = itemStack.getCount();
|
if (ret == null) {
|
||||||
itemStack.setCount( 1 );
|
ret = new AESharedItemStack(itemStack.copy());
|
||||||
|
REGISTRY.put(ret, new WeakReference<>(ret));
|
||||||
|
}
|
||||||
|
itemStack.setCount(oldStackSize);
|
||||||
|
|
||||||
AESharedItemStack search = new AESharedItemStack( itemStack );
|
return ret;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,263 +18,76 @@
|
|||||||
|
|
||||||
package appeng.util.item;
|
package appeng.util.item;
|
||||||
|
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
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>
|
public AESharedItemStack(final ItemStack itemStack) {
|
||||||
{
|
this(itemStack, itemStack.getItemDamage());
|
||||||
private static final NBTTagCompound LOW_TAG = new NBTTagCompound();
|
}
|
||||||
private static final NBTTagCompound HIGH_TAG = new NBTTagCompound();
|
|
||||||
|
|
||||||
private final ItemStack itemStack;
|
/**
|
||||||
private final int itemId;
|
* A constructor to explicitly set the damage value and not fetch it from the {@link ItemStack}
|
||||||
private final int itemDamage;
|
*
|
||||||
private final int hashCode;
|
* @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 )
|
// Ensure this is always called last.
|
||||||
{
|
this.hashCode = this.makeHashCode();
|
||||||
this.itemStack = itemStack;
|
}
|
||||||
this.itemId = Item.getIdFromItem( itemStack.getItem() );
|
|
||||||
this.itemDamage = itemStack.getItemDamage();
|
|
||||||
this.hashCode = this.makeHashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
Bounds getBounds( final FuzzyMode fuzzy, final boolean ignoreMeta )
|
ItemStack getDefinition() {
|
||||||
{
|
return this.itemStack;
|
||||||
return new Bounds( this.itemStack, fuzzy, ignoreMeta );
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack getDefinition()
|
int getItemDamage() {
|
||||||
{
|
return this.itemDamage;
|
||||||
return this.itemStack;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int getItemDamage()
|
@Override
|
||||||
{
|
public int hashCode() {
|
||||||
return this.itemDamage;
|
return this.hashCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getItemID()
|
@Override
|
||||||
{
|
public boolean equals(final Object obj) {
|
||||||
return this.itemId;
|
if (this == obj) {
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
|
if (!(obj instanceof AESharedItemStack)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
final AESharedItemStack other = (AESharedItemStack) obj;
|
||||||
public int hashCode()
|
Preconditions.checkState(this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1");
|
||||||
{
|
Preconditions.checkArgument(other.getDefinition().getCount() == 1, "ItemStack#getCount() has to be 1");
|
||||||
return this.hashCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (this.itemStack == other.itemStack) {
|
||||||
public boolean equals( final Object obj )
|
return true;
|
||||||
{
|
}
|
||||||
if( obj instanceof AESharedItemStack )
|
return ItemStack.areItemStacksEqual(this.itemStack, other.itemStack);
|
||||||
{
|
}
|
||||||
final AESharedItemStack other = (AESharedItemStack) obj;
|
|
||||||
|
|
||||||
Preconditions.checkState( this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1" );
|
private int makeHashCode() {
|
||||||
Preconditions.checkArgument( other.getDefinition().getCount() == 1, "ItemStack#getCount() has to be 1" );
|
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;
|
package appeng.util.item;
|
||||||
|
|
||||||
|
import appeng.api.storage.data.IAEStack;
|
||||||
import io.netty.buffer.ByteBuf;
|
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;
|
protected static long getPacketValue( final byte type, final ByteBuf tag )
|
||||||
private long stackSize;
|
{
|
||||||
private long countRequestable;
|
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 )
|
return tag.readLong();
|
||||||
{
|
}
|
||||||
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();
|
@Override
|
||||||
}
|
public long getStackSize() {
|
||||||
|
return this.stackSize;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getStackSize()
|
public T setStackSize(final long ss) {
|
||||||
{
|
this.stackSize = ss;
|
||||||
return this.stackSize;
|
return (T) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StackType setStackSize( final long ss )
|
public long getCountRequestable() {
|
||||||
{
|
return this.countRequestable;
|
||||||
this.stackSize = ss;
|
}
|
||||||
return (StackType) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getCountRequestable()
|
public T setCountRequestable(final long countRequestable) {
|
||||||
{
|
this.countRequestable = countRequestable;
|
||||||
return this.countRequestable;
|
return (T) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StackType setCountRequestable( final long countRequestable )
|
public boolean isCraftable() {
|
||||||
{
|
return this.isCraftable;
|
||||||
this.countRequestable = countRequestable;
|
}
|
||||||
return (StackType) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCraftable()
|
public T setCraftable(final boolean isCraftable) {
|
||||||
{
|
this.isCraftable = isCraftable;
|
||||||
return this.isCraftable;
|
return (T) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StackType setCraftable( final boolean isCraftable )
|
public T reset() {
|
||||||
{
|
this.stackSize = 0;
|
||||||
this.isCraftable = isCraftable;
|
this.setCountRequestable(0);
|
||||||
return (StackType) this;
|
this.setCraftable(false);
|
||||||
}
|
return (T) this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StackType reset()
|
public T empty() {
|
||||||
{
|
final T dup = this.copy();
|
||||||
this.stackSize = 0;
|
dup.reset();
|
||||||
// priority = Integer.MIN_VALUE;
|
return dup;
|
||||||
this.setCountRequestable( 0 );
|
}
|
||||||
this.setCraftable( false );
|
|
||||||
return (StackType) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StackType empty()
|
public boolean isMeaningful() {
|
||||||
{
|
return this.stackSize != 0 || this.countRequestable > 0 || this.isCraftable;
|
||||||
final StackType dup = this.copy();
|
}
|
||||||
dup.reset();
|
|
||||||
return dup;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMeaningful()
|
public void incStackSize(final long i) {
|
||||||
{
|
this.stackSize += i;
|
||||||
return this.stackSize != 0 || this.countRequestable > 0 || this.isCraftable;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void incStackSize( final long i )
|
public void decStackSize(final long i) {
|
||||||
{
|
this.stackSize -= i;
|
||||||
this.stackSize += i;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decStackSize( final long i )
|
public void incCountRequestable(final long i) {
|
||||||
{
|
this.countRequestable += i;
|
||||||
this.stackSize -= i;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void incCountRequestable( final long i )
|
public void decCountRequestable(final long i) {
|
||||||
{
|
this.countRequestable -= i;
|
||||||
this.countRequestable += i;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
protected byte getType( final long num )
|
||||||
public void decCountRequestable( final long i )
|
{
|
||||||
{
|
if( num <= 255 )
|
||||||
this.countRequestable -= i;
|
{
|
||||||
}
|
return 0;
|
||||||
|
}
|
||||||
|
else if( num <= 65535 )
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if( num <= 4294967295L )
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected byte getType( final long num )
|
protected abstract boolean hasTagCompound();
|
||||||
{
|
|
||||||
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 void putPacketValue( final ByteBuf tag, final long num )
|
||||||
|
{
|
||||||
protected void putPacketValue( final ByteBuf tag, final long num )
|
if( num <= 255 )
|
||||||
{
|
{
|
||||||
if( num <= 255 )
|
tag.writeByte( (byte) ( num + Byte.MIN_VALUE ) );
|
||||||
{
|
}
|
||||||
tag.writeByte( (byte) ( num + Byte.MIN_VALUE ) );
|
else if( num <= 65535 )
|
||||||
}
|
{
|
||||||
else if( num <= 65535 )
|
tag.writeShort( (short) ( num + Short.MIN_VALUE ) );
|
||||||
{
|
}
|
||||||
tag.writeShort( (short) ( num + Short.MIN_VALUE ) );
|
else if( num <= 4294967295L )
|
||||||
}
|
{
|
||||||
else if( num <= 4294967295L )
|
tag.writeInt( (int) ( num + Integer.MIN_VALUE ) );
|
||||||
{
|
}
|
||||||
tag.writeInt( (int) ( num + Integer.MIN_VALUE ) );
|
else
|
||||||
}
|
{
|
||||||
else
|
tag.writeLong( num );
|
||||||
{
|
}
|
||||||
tag.writeLong( num );
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,190 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Applied Energistics 2.
|
||||||
|
* Copyright (c) 2021, TeamAppliedEnergistics, All rights reserved.
|
||||||
|
*
|
||||||
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package appeng.util.item;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectAVLTreeMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Object2ObjectSortedMap;
|
||||||
|
|
||||||
|
import appeng.api.config.FuzzyMode;
|
||||||
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This variant list is optimized for damageable items, and supports selecting durability ranges with
|
||||||
|
* {@link #findFuzzy(IAEItemStack, FuzzyMode)}.
|
||||||
|
*/
|
||||||
|
class FuzzyItemVariantList extends ItemVariantList {
|
||||||
|
|
||||||
|
static final SharedStackComparator COMPARATOR = new SharedStackComparator();
|
||||||
|
|
||||||
|
// NOTE: We only use Object as they key here so we can pass our special DamageBounds to the subMap method.
|
||||||
|
// We NEVER put any keys in this map that are not AESharedItemStacks.
|
||||||
|
private final Object2ObjectSortedMap<Object, IAEItemStack> records = new Object2ObjectAVLTreeMap<>(COMPARATOR);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<IAEItemStack> findFuzzy(final IAEItemStack filter, final FuzzyMode fuzzy) {
|
||||||
|
ItemStack itemStack = filter.getDefinition();
|
||||||
|
|
||||||
|
ItemDamageBound lowerBound = makeLowerBound(itemStack, fuzzy);
|
||||||
|
ItemDamageBound upperBound = makeUpperBound(itemStack, fuzzy);
|
||||||
|
Preconditions.checkState(lowerBound.itemDamage > upperBound.itemDamage);
|
||||||
|
|
||||||
|
return this.records.subMap(lowerBound, upperBound).values();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@Override
|
||||||
|
Map<AESharedItemStack, IAEItemStack> getRecords() {
|
||||||
|
// We ensure on our end that we NEVER use anything but AESharedItemStack as the key in this map
|
||||||
|
return (Map<AESharedItemStack, IAEItemStack>) (Object) this.records;
|
||||||
|
}
|
||||||
|
|
||||||
|
static class ItemDamageBound {
|
||||||
|
final int itemDamage;
|
||||||
|
|
||||||
|
public ItemDamageBound(int itemDamage) {
|
||||||
|
this.itemDamage = itemDamage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This comparator creates a strict and total ordering over all {@link AESharedItemStack} of the same item. To
|
||||||
|
* support selecting ranges of durability, it is defined for type {@link Object} and also accepts
|
||||||
|
* {@link ItemDamageBound} as an argument to compare against.
|
||||||
|
*/
|
||||||
|
static class SharedStackComparator implements Comparator<Object> {
|
||||||
|
@Override
|
||||||
|
public int compare(Object a, Object b) {
|
||||||
|
// Either argument can either be a damage bound or a shared item stack
|
||||||
|
// Since we never put damage bounds into the map as keys, only one
|
||||||
|
// of the two arguments can possibly be a bound
|
||||||
|
ItemDamageBound boundA = null;
|
||||||
|
AESharedItemStack stackA = null;
|
||||||
|
int itemDamageA;
|
||||||
|
if (a instanceof ItemDamageBound) {
|
||||||
|
boundA = (ItemDamageBound) a;
|
||||||
|
itemDamageA = boundA.itemDamage;
|
||||||
|
} else {
|
||||||
|
stackA = (AESharedItemStack) a;
|
||||||
|
itemDamageA = stackA.getItemDamage();
|
||||||
|
}
|
||||||
|
ItemDamageBound boundB = null;
|
||||||
|
AESharedItemStack stackB = null;
|
||||||
|
int itemDamageB;
|
||||||
|
if (b instanceof ItemDamageBound) {
|
||||||
|
boundB = (ItemDamageBound) b;
|
||||||
|
itemDamageB = boundB.itemDamage;
|
||||||
|
} else {
|
||||||
|
stackB = (AESharedItemStack) b;
|
||||||
|
itemDamageB = stackB.getItemDamage();
|
||||||
|
}
|
||||||
|
|
||||||
|
// When either argument is a damage bound, we just compare the damage values because it is used
|
||||||
|
// only to get a certain damage range out of the map.
|
||||||
|
if (boundA != null || boundB != null) {
|
||||||
|
return Integer.compare(itemDamageB, itemDamageA);
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack itemStackA = stackA.getDefinition();
|
||||||
|
ItemStack itemStackB = stackB.getDefinition();
|
||||||
|
Preconditions.checkState(itemStackA.getCount() == 1, "ItemStack#getCount() has to be 1");
|
||||||
|
Preconditions.checkArgument(itemStackB.getCount() == 1, "ItemStack#getCount() has to be 1");
|
||||||
|
|
||||||
|
if (itemStackA == itemStackB) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Damaged items are sorted before undamaged items
|
||||||
|
final int damageValue = Integer.compare(itemDamageB, itemDamageA);
|
||||||
|
if (damageValue != 0) {
|
||||||
|
return damageValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// As a final tie breaker, order by the object identity of the item stack
|
||||||
|
// While this will order seemingly at random, we only need the order of
|
||||||
|
// damage values to be predictable, while still having to satisfy the
|
||||||
|
// complete order requirements of the sorted map
|
||||||
|
return Long.compare(System.identityHashCode(itemStackA), System.identityHashCode(itemStackB));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minecraft reverses the damage values. So anything with a damage of 0 is undamaged and increases the more damaged
|
||||||
|
* the item is.
|
||||||
|
* <p>
|
||||||
|
* Further the used subMap follows [MAX_DAMAGE, MIN_DAMAGE), so to include undamaged items, we have to start with a
|
||||||
|
* lower damage value than 0, while it is fine to use {@link ItemStack#getMaxDamage()} for the upper bound.
|
||||||
|
*/
|
||||||
|
private static final int MIN_DAMAGE_VALUE = -1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Keep in mind that the stack order is from most damaged to least damaged, so this lower bound will actually be a
|
||||||
|
* higher number than the upper bound.
|
||||||
|
*/
|
||||||
|
static ItemDamageBound makeLowerBound(final ItemStack stack, final FuzzyMode fuzzy)
|
||||||
|
{
|
||||||
|
Preconditions.checkState( stack.getItem().isDamageable(), "Item#isDamageable() has to be true" );
|
||||||
|
|
||||||
|
int damage;
|
||||||
|
if( fuzzy == FuzzyMode.IGNORE_ALL )
|
||||||
|
{
|
||||||
|
if( stack.getMaxDamage() == 0 )
|
||||||
|
{
|
||||||
|
damage = stack.getItemDamage();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
damage = stack.getMaxDamage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
final int breakpoint = fuzzy.calculateBreakPoint( stack.getMaxDamage() );
|
||||||
|
damage = stack.getItemDamage() <= breakpoint ? breakpoint : stack.getMaxDamage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ItemDamageBound( damage );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Keep in mind that the stack order is from most damaged to least damaged, so this upper bound will actually be a
|
||||||
|
* lower number than the lower bound. It also is exclusive.
|
||||||
|
*/
|
||||||
|
static ItemDamageBound makeUpperBound(final ItemStack stack, final FuzzyMode fuzzy) {
|
||||||
|
Preconditions.checkState(stack.getItem().isDamageable(), "Item#isDamageable() has to be true");
|
||||||
|
|
||||||
|
int damage;
|
||||||
|
if (fuzzy == FuzzyMode.IGNORE_ALL) {
|
||||||
|
damage = MIN_DAMAGE_VALUE;
|
||||||
|
} else {
|
||||||
|
final int breakpoint = fuzzy.calculateBreakPoint(stack.getMaxDamage());
|
||||||
|
damage = stack.getItemDamage() <= breakpoint ? MIN_DAMAGE_VALUE : breakpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ItemDamageBound(damage);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of Applied Energistics 2.
|
* 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
|
* 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
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -18,212 +18,196 @@
|
|||||||
|
|
||||||
package appeng.util.item;
|
package appeng.util.item;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.ConcurrentModificationException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NavigableMap;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.concurrent.ConcurrentSkipListMap;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraft.item.Item;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
|
||||||
|
|
||||||
import appeng.api.config.FuzzyMode;
|
import appeng.api.config.FuzzyMode;
|
||||||
import appeng.api.storage.data.IAEItemStack;
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
import appeng.api.storage.data.IItemList;
|
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
|
ItemVariantList record = this.records.get(itemStack.getItem());
|
||||||
public void add( final IAEItemStack option )
|
return record != null ? record.findPrecise(itemStack) : null;
|
||||||
{
|
}
|
||||||
if( option == null )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 )
|
ItemVariantList record = this.records.get(filter.getItem());
|
||||||
{
|
return record != null ? record.findFuzzy(filter, fuzzy) : Collections.emptyList();
|
||||||
st.add( option );
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
if (itemStack == null) {
|
||||||
public IAEItemStack findPrecise( final IAEItemStack itemStack )
|
return;
|
||||||
{
|
}
|
||||||
if( itemStack == null )
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.records.get( ( (AEItemStack) itemStack ).getSharedStack() );
|
this.getOrCreateRecord(itemStack.getItem()).add(itemStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<IAEItemStack> findFuzzy( final IAEItemStack filter, final FuzzyMode fuzzy )
|
public void addStorage(final IAEItemStack itemStack) {
|
||||||
{
|
version.incrementAndGet();
|
||||||
if( filter == null )
|
|
||||||
{
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
final AEItemStack ais = (AEItemStack) filter;
|
if (itemStack == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return ais.getOre().map( or ->
|
this.getOrCreateRecord(itemStack.getItem()).addStorage(itemStack);
|
||||||
{
|
}
|
||||||
if( or.getAEEquivalents().size() == 1 )
|
|
||||||
{
|
|
||||||
final IAEItemStack is = or.getAEEquivalents().get( 0 );
|
|
||||||
|
|
||||||
return this.findFuzzyDamage( is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE );
|
@Override
|
||||||
}
|
public void addCrafting(final IAEItemStack itemStack) {
|
||||||
else
|
version.incrementAndGet();
|
||||||
{
|
|
||||||
final Collection<IAEItemStack> output = new ArrayList<>();
|
|
||||||
|
|
||||||
for( final IAEItemStack is : or.getAEEquivalents() )
|
if (itemStack == null) {
|
||||||
{
|
return;
|
||||||
output.addAll( this.findFuzzyDamage( is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) );
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
this.getOrCreateRecord(itemStack.getItem()).addCrafting(itemStack);
|
||||||
}
|
}
|
||||||
} ).orElse( this.findFuzzyDamage( ais, fuzzy, false ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEmpty()
|
public void addRequestable(final IAEItemStack itemStack) {
|
||||||
{
|
version.incrementAndGet();
|
||||||
return !this.iterator().hasNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (itemStack == null) {
|
||||||
public void addStorage( final IAEItemStack option )
|
return;
|
||||||
{
|
}
|
||||||
if( option == null )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final IAEItemStack st = this.records.get( ( (AEItemStack) option ).getSharedStack() );
|
this.getOrCreateRecord(itemStack.getItem()).addRequestable(itemStack);
|
||||||
|
}
|
||||||
|
|
||||||
if( st != null )
|
@Override
|
||||||
{
|
public IAEItemStack getFirstItem() {
|
||||||
st.incStackSize( option.getStackSize() );
|
for (final IAEItemStack stackType : this) {
|
||||||
return;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
return size;
|
||||||
* public void clean() { Iterator<StackType> i = iterator(); while (i.hasNext()) { StackType AEI =
|
}
|
||||||
* i.next(); if ( !AEI.isMeaningful() ) i.remove(); } }
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCrafting( final IAEItemStack option )
|
public Iterator<IAEItemStack> iterator() {
|
||||||
{
|
return new ChainedIterator(this.records.values().iterator(), version);
|
||||||
if( option == null )
|
}
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final IAEItemStack st = this.records.get( ( (AEItemStack) option ).getSharedStack() );
|
@Override
|
||||||
|
public void resetStatus() {
|
||||||
|
for (final IAEItemStack i : this) {
|
||||||
|
i.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if( st != null )
|
private ItemVariantList getOrCreateRecord(Item item) {
|
||||||
{
|
return this.records.computeIfAbsent(item, this::makeRecordMap);
|
||||||
st.setCraftable( true );
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final IAEItemStack opt = option.copy();
|
private ItemVariantList makeRecordMap(Item item) {
|
||||||
opt.setStackSize( 0 );
|
if (item.isDamageable()) {
|
||||||
opt.setCraftable( true );
|
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
|
private final AtomicInteger parentVersion;
|
||||||
public void addRequestable( final IAEItemStack option )
|
private final int version;
|
||||||
{
|
private final Iterator<ItemVariantList> parent;
|
||||||
if( option == null )
|
private Iterator<IAEItemStack> next;
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 )
|
@Override
|
||||||
{
|
public boolean hasNext() {
|
||||||
st.setCountRequestable( st.getCountRequestable() + option.getCountRequestable() );
|
return next != null && next.hasNext();
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
final IAEItemStack opt = option.copy();
|
@Override
|
||||||
opt.setStackSize( 0 );
|
public IAEItemStack next() {
|
||||||
opt.setCraftable( false );
|
if (this.next == null) {
|
||||||
opt.setCountRequestable( option.getCountRequestable() );
|
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
|
private void ensureItems() {
|
||||||
public IAEItemStack getFirstItem()
|
if (hasNext()) {
|
||||||
{
|
return; // Still items left in the current one
|
||||||
for( final IAEItemStack stackType : this )
|
}
|
||||||
{
|
|
||||||
return stackType;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
// Find the next iterator willing to return some items...
|
||||||
}
|
while (this.parent.hasNext()) {
|
||||||
|
this.next = this.parent.next().iterator();
|
||||||
|
|
||||||
@Override
|
if (this.next.hasNext()) {
|
||||||
public int size()
|
return; // Found one!
|
||||||
{
|
}
|
||||||
return this.records.size();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
// No more items
|
||||||
public Iterator<IAEItemStack> iterator()
|
this.next = null;
|
||||||
{
|
}
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
* 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
|
* 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
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
@@ -18,59 +18,53 @@
|
|||||||
|
|
||||||
package appeng.util.item;
|
package appeng.util.item;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import appeng.api.storage.data.IAEItemStack;
|
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;
|
@Override
|
||||||
private T next;
|
public boolean hasNext() {
|
||||||
|
return this.next != null;
|
||||||
|
}
|
||||||
|
|
||||||
public MeaningfulItemIterator( final Iterator<T> iterator )
|
@Override
|
||||||
{
|
public T next() {
|
||||||
this.parent = iterator;
|
if (this.next == null) {
|
||||||
}
|
throw new NoSuchElementException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
T result = this.next;
|
||||||
public boolean hasNext()
|
this.next = this.seekNext();
|
||||||
{
|
return result;
|
||||||
while( this.parent.hasNext() )
|
}
|
||||||
{
|
|
||||||
this.next = this.parent.next();
|
|
||||||
|
|
||||||
if( this.next.isMeaningful() )
|
private T seekNext() {
|
||||||
{
|
while (this.parent.hasNext()) {
|
||||||
return true;
|
T item = this.parent.next();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.parent.remove(); // self cleaning :3
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.next = null;
|
if (item.isMeaningful()) {
|
||||||
return false;
|
return item;
|
||||||
}
|
} else {
|
||||||
|
this.parent.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
return null;
|
||||||
public T next()
|
}
|
||||||
{
|
|
||||||
if( this.next == null )
|
|
||||||
{
|
|
||||||
throw new NoSuchElementException();
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.next;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove()
|
|
||||||
{
|
|
||||||
this.parent.remove();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Applied Energistics 2.
|
||||||
|
* Copyright (c) 2021, TeamAppliedEnergistics, All rights reserved.
|
||||||
|
*
|
||||||
|
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package appeng.util.item;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
|
||||||
|
|
||||||
|
import appeng.api.config.FuzzyMode;
|
||||||
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This variant list is optimized for items that cannot be damaged and thus do not support querying durability ranges
|
||||||
|
* via {@link #findFuzzy(IAEItemStack, FuzzyMode)}.
|
||||||
|
*/
|
||||||
|
class NormalItemVariantList extends ItemVariantList {
|
||||||
|
|
||||||
|
private final Reference2ObjectMap<AESharedItemStack, IAEItemStack> records = new Reference2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Map<AESharedItemStack, IAEItemStack> getRecords() {
|
||||||
|
return this.records;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For items that do not support durability, we just return all variants to a fuzzy search.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Collection<IAEItemStack> findFuzzy(IAEItemStack filter, FuzzyMode fuzzy) {
|
||||||
|
return this.getRecords().values();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+2
-2
@@ -4,8 +4,8 @@
|
|||||||
"type": "forge:and",
|
"type": "forge:and",
|
||||||
"values": [
|
"values": [
|
||||||
{
|
{
|
||||||
"type": "minecraft:item_exists",
|
"type": "appliedenergistics2:part_exists",
|
||||||
"item": "appliedenergistics2:part:part.terminal"
|
"part": "part.terminal"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "appliedenergistics2:material_exists",
|
"type": "appliedenergistics2:material_exists",
|
||||||
|
|||||||
Reference in New Issue
Block a user