Compare commits

..

4 Commits

44 changed files with 456 additions and 1119 deletions
+2 -13
View File
@@ -15,10 +15,6 @@ Fixes:
- 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.
- Fix CME exceptions on the energy grid
- Fix AE going offline even with enough power by extracting from the local buffer always last
- Fix IO-Port copying craftable flag into items
- Fix NBT of old items not clearing on drives that reached 64 types once
Performance:
@@ -28,9 +24,6 @@ Performance:
- 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
- Reduced import bus insert simulation to 1 before real insertion (if possible)
- Backported itemlist re-implementation along with pattern changes to avoid CraftingManager fallback issues
- Instead of recalculating all the content of the network on every change, track the changes properly and apply them to the cached list of items
QOL:
@@ -38,7 +31,7 @@ QOL:
- 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)
- 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 )
@@ -46,11 +39,7 @@ QOL:
- 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
- GTCE Blocking mode work through phantom itemfaces
- Shift-clicking blank patterns into the pattern terminal will try to fill the blank pattern slots first
- Mismached simulated/real item count ( most often due to compacting drawers ) will now tell the player wich item cause the failure when trying to start a craft
- Added 'pattern expansion' cards that adds an extra row of patterns to interfaces. up to 3 card on an interface. (each card will increase the interface idle power draw by 4 times)
-JEI auto switches between crafting and processing patterns
HOTKEYS:
+1 -1
View File
@@ -3,7 +3,7 @@ aechannel=stable
aebuild=7
aegroup=appeng
aebasename=appliedenergistics2
trousers=omni-fixes-v47
trousers=omni-fixes-v44
#########################################################
# Versions #
@@ -47,5 +47,5 @@ public interface IStackWatcherHost
* @param diffStack new stack
* @param chan storage channel
*/
void onStackChange( IItemList<?> o, IAEStack<?> fullStack, IAEStack<?> diffStack, IActionSource src, IStorageChannel<?> chan );
void onStackChange( IAEStack<?> diffStack, IStorageChannel<?> chan );
}
@@ -51,7 +51,6 @@ public interface IStorageGrid extends IGridCache, IStorageMonitorable
* @param input injected items
*/
void postAlterationOfStoredItems( IStorageChannel<?> chan, Iterable<? extends IAEStack<?>> input, IActionSource src );
void postCraftablesChanges( IStorageChannel<?> chan, Iterable<? extends IAEStack<?>> input, IActionSource src);
/**
* Used to add a cell provider to the storage system
@@ -52,4 +52,9 @@ public interface IMEMonitorHandlerReceiver<T extends IAEStack<T>>
* called when the list updates its contents, this is mostly for handling power events.
*/
void onListUpdate();
default boolean hasListeners()
{
return true;
}
}
@@ -237,11 +237,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
int interfaceDim = dimHashMap.get( guiButtonHashMap.get( this.selectedButton ) );
if( playerDim != interfaceDim )
{
try {
mc.player.sendStatusMessage( new TextComponentString( "Interface located at dimension: " + interfaceDim + " [" + DimensionManager.getWorld( interfaceDim ).provider.getDimensionType().getName() + "] and cant be highlighted" ), false );
} catch(Exception e){
mc.player.sendStatusMessage( new TextComponentString( "Interface is located in another dimension and cannot be highlighted" ), false );
}
mc.player.sendStatusMessage( new TextComponentString( "Interface located at dimension: " + interfaceDim + " [" + DimensionManager.getWorld( interfaceDim ).provider.getDimensionType().getName() + "] and cant be highlighted" ), false );
}
else
{
@@ -270,15 +270,12 @@ public class GuiUpgradeable extends AEBaseGui implements IJEIGhostIngredients
@Override
public Rectangle getArea()
{
if( slot instanceof SlotFake && ( (SlotFake) slot ).isSlotEnabled() )
{
if( slot instanceof SlotFake )
return new Rectangle( getGuiLeft() + ( (SlotFake) slot ).xPos, getGuiTop() + ( (SlotFake) slot ).yPos, 16, 16 );
}
else if( slot instanceof GuiFluidSlot && ( (GuiFluidSlot) slot ).isSlotEnabled() )
else
{
return new Rectangle( getGuiLeft() + ( (GuiFluidSlot) slot ).xPos(), getGuiTop() + ( (GuiFluidSlot) slot ).yPos(), 16, 16 );
}
return new Rectangle();
}
@Override
@@ -287,7 +284,7 @@ public class GuiUpgradeable extends AEBaseGui implements IJEIGhostIngredients
PacketInventoryAction p = null;
try
{
if( slot instanceof SlotFake && ( (SlotFake) slot ).isSlotEnabled() )
if( slot instanceof SlotFake )
{
if( finalItemStack.isEmpty() && finalFluidStack != null )
{
@@ -10,9 +10,9 @@ import net.minecraft.item.ItemStack;
public abstract class GuiCustomSlot extends Gui implements ITooltip
{
protected final int x;
protected final int y;
protected final int id;
private final int x;
private final int y;
private final int id;
public GuiCustomSlot( final int id, final int x, final int y )
{
@@ -245,10 +245,7 @@ public class PacketJEIRecipe extends AppEngPacket
if( out != null )
{
if (!cct.useRealItems())
{
out.setStackSize( recipe[x][y].getCount() );
}
out.setStackSize( recipe[x][y].getCount() );
currentItem = out.createItemStack();
}
}
@@ -19,7 +19,6 @@
package appeng.core.sync.packets;
import appeng.fluids.container.ContainerFluidInterface;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@@ -91,9 +90,5 @@ public class PacketTargetFluidStack extends AppEngPacket
{
( (ContainerFluidTerminal) player.openContainer ).setTargetStack( this.stack );
}
else if( player.openContainer instanceof ContainerFluidInterface )
{
( (ContainerFluidInterface) player.openContainer ).setTargetStack( this.stack );
}
}
}
+7 -67
View File
@@ -22,7 +22,6 @@ package appeng.crafting;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
import appeng.me.cache.CraftingGridCache;
import com.google.common.base.Stopwatch;
import net.minecraft.entity.player.EntityPlayer;
@@ -60,7 +59,6 @@ public class CraftingJob implements Runnable, ICraftingJob
private final IItemList<IAEItemStack> missing = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
private final HashMap<String, TwoIntegers> opsAndMultiplier = new HashMap<>();
private final Object monitor = new Object();
private final Stopwatch watch = Stopwatch.createUnstarted();
private CraftingTreeNode tree;
private final IAEItemStack output;
private boolean simulate = false;
@@ -68,12 +66,7 @@ public class CraftingJob implements Runnable, ICraftingJob
private long bytes = 0;
private final IActionSource actionSrc;
private final ICraftingCallback callback;
private boolean running = false;
private boolean done = false;
private int time;
private int incTime;
private final ICraftingGrid cc;
private final IStorageGrid sg;
private World wrapWorld( final World w )
{
@@ -87,9 +80,10 @@ public class CraftingJob implements Runnable, ICraftingJob
this.actionSrc = actionSrc;
this.callback = callback;
this.cc = grid.getCache( ICraftingGrid.class );
this.sg = grid.getCache( IStorageGrid.class );
this.original = new MECraftingInventory( sg.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ), actionSrc, false, false, false );
final ICraftingGrid cc = grid.getCache( ICraftingGrid.class );
final IStorageGrid sg = grid.getCache( IStorageGrid.class );
this.original = new MECraftingInventory( sg
.getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ), actionSrc, false, false, false );
this.setTree( this.getCraftingTree( cc, what ) );
this.availableCheck = null;
@@ -139,7 +133,6 @@ public class CraftingJob implements Runnable, ICraftingJob
try
{
TickHandler.INSTANCE.registerCraftingSimulation( this.world, this );
this.handlePausing();
final Stopwatch timer = Stopwatch.createStarted();
@@ -221,41 +214,6 @@ public class CraftingJob implements Runnable, ICraftingJob
this.finish();
}
void handlePausing() throws InterruptedException
{
if( !this.actionSrc.player().isPresent() && this.incTime > 100 )
{
this.incTime = 0;
synchronized ( this.monitor )
{
if( this.watch.elapsed( TimeUnit.MICROSECONDS ) > this.time )
{
this.running = false;
this.watch.stop();
this.monitor.notify();
}
if( !this.running )
{
AELog.craftingDebug( "crafting job will now sleep" );
while ( !this.running )
{
this.monitor.wait();
}
AELog.craftingDebug( "crafting job now active" );
}
}
if( Thread.interrupted() )
{
throw new InterruptedException();
}
}
this.incTime++;
}
private void finish()
{
if( this.callback != null )
@@ -267,7 +225,6 @@ public class CraftingJob implements Runnable, ICraftingJob
synchronized( this.monitor )
{
this.running = false;
this.done = true;
this.monitor.notify();
}
@@ -313,25 +270,13 @@ public class CraftingJob implements Runnable, ICraftingJob
/**
* @return true if this needs more simulation
*/
public boolean simulateFor(final int milli)
public boolean simulateFor()
{
this.time = milli;
synchronized ( this.monitor )
{
if( this.done )
{
synchronized( this.monitor ) {
if ( this.done ) {
return false;
}
if( !this.actionSrc.player().isPresent() )
{
this.watch.reset();
this.watch.start();
this.monitor.notify();
}
this.running = true;
}
return true;
}
@@ -382,11 +327,6 @@ public class CraftingJob implements Runnable, ICraftingJob
}
}
public void addIncompletablePattern( ICraftingPatternDetails details, IAEItemStack stack )
{
( (CraftingGridCache) cc ).getPatternStatusManager().put( details, stack );
}
private static class TwoIntegers
{
private final long perOp = 0;
@@ -22,10 +22,7 @@ package appeng.crafting;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import appeng.util.item.OreHelper;
import appeng.util.item.OreReference;
import com.google.common.collect.Lists;
import net.minecraft.world.World;
@@ -120,14 +117,9 @@ public class CraftingTreeNode
return this.parent.notRecursive( details );
}
public CraftingTreeProcess getParent()
{
return parent;
}
IAEItemStack request( final MECraftingInventory inv, long l, final IActionSource src ) throws CraftBranchFailure, InterruptedException
{
this.job.handlePausing();
final List<IAEItemStack> thingsUsed = new ArrayList<>();
this.what.setStackSize( l );
@@ -326,7 +318,6 @@ public class CraftingTreeNode
if( this.missing > 0 )
{
job.addMissing( this.getStack( this.missing ) );
addMissingIAEStack();
}
// missing = 0;
@@ -338,29 +329,6 @@ public class CraftingTreeNode
}
}
void addMissingIAEStack()
{
if( parent != null )
{
parent.addMissingIAEStack();
if( missing > 0 )
{
if( this.parent.details.canSubstitute() && this.getSlot() >= 0 )
{
final List<IAEItemStack> substitutes = this.parent.details.getSubstituteInputs( this.slot );
for( IAEItemStack stack : substitutes )
{
job.addIncompletablePattern( this.getParent().details, stack.copy().setStackSize( this.missing ) );
}
}
else
{
job.addIncompletablePattern( this.getParent().details, this.getStack( this.missing ) );
}
}
}
}
IAEItemStack getStack( final long size )
{
final IAEItemStack is = this.what.copy();
@@ -23,10 +23,11 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import appeng.me.cache.CraftingGridCache;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.FMLCommonHandler;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
@@ -65,7 +66,7 @@ public class CraftingTreeProcess
this.depth = depth;
final World world = job.getWorld();
if( !( (CraftingGridCache) cc ).getPatternStatusManager().containsIncompletablePattern( details ) && details.isCraftable() )
if( details.isCraftable() )
{
final IAEItemStack[] list = details.getInputs();
@@ -173,11 +174,6 @@ public class CraftingTreeProcess
return this.parent == null || this.parent.notRecursive( details );
}
public CraftingTreeNode getParent()
{
return parent;
}
long getTimes( final long remaining, final long stackSize )
{
if( this.limitQty || this.fullSimulation )
@@ -189,7 +185,7 @@ public class CraftingTreeProcess
void request( final MECraftingInventory inv, final long i, final IActionSource src ) throws CraftBranchFailure, InterruptedException
{
this.job.handlePausing();
if( this.fullSimulation )
{
final InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
@@ -321,12 +317,4 @@ public class CraftingTreeProcess
pro.getPlan( plan );
}
}
public void addMissingIAEStack()
{
if( parent != null )
{
parent.addMissingIAEStack();
}
}
}
@@ -21,9 +21,6 @@ package appeng.fluids.client.gui;
import java.io.IOException;
import appeng.api.util.IConfigManager;
import appeng.client.gui.widgets.GuiCustomSlot;
import appeng.util.IConfigManagerHost;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.entity.player.InventoryPlayer;
@@ -41,12 +38,11 @@ import appeng.fluids.helper.IFluidInterfaceHost;
import appeng.fluids.util.IAEFluidTank;
public class GuiFluidInterface extends GuiUpgradeable implements IConfigManagerHost
public class GuiFluidInterface extends GuiUpgradeable
{
public final static int ID_BUTTON_TANK = 222;
private final IFluidInterfaceHost host;
private final ContainerFluidInterface container;
private GuiTabButton priority;
public GuiFluidInterface( final InventoryPlayer ip, final IFluidInterfaceHost te )
@@ -54,8 +50,6 @@ public class GuiFluidInterface extends GuiUpgradeable implements IConfigManagerH
super( new ContainerFluidInterface( ip, te ) );
this.ySize = 231;
this.host = te;
( this.container = (ContainerFluidInterface) this.inventorySlots ).setGui( this );
}
@Override
@@ -68,7 +62,9 @@ public class GuiFluidInterface extends GuiUpgradeable implements IConfigManagerH
for( int i = 0; i < DualityFluidInterface.NUMBER_OF_TANKS; ++i )
{
this.guiSlots.add( new GuiFluidTank( fluidTank, i, DualityFluidInterface.NUMBER_OF_TANKS + i, 36 + 18 * i, 53, 16, 68 ) );
final GuiFluidTank guiTank = new GuiFluidTank( fluidTank, i, DualityFluidInterface.NUMBER_OF_TANKS + i, this.getGuiLeft() + 35 + 18 * i, this
.getGuiTop() + 53, 16, 68 );
this.buttonList.add( guiTank );
this.guiSlots.add( new GuiFluidSlot( configFluids, i, i, 35 + 18 * i, 35 ) );
}
@@ -108,33 +104,9 @@ public class GuiFluidInterface extends GuiUpgradeable implements IConfigManagerH
}
}
@Override
protected void mouseClicked( int xCoord, int yCoord, int btn ) throws IOException
{
for( GuiCustomSlot slot : this.guiSlots )
{
if( slot instanceof GuiFluidTank )
{
if( this.isPointInRegion( slot.xPos(), slot.yPos(), slot.getWidth(), slot.getHeight(), xCoord, yCoord ) && slot.canClick( this.mc.player ) )
{
this.container.setTargetStack( ( (GuiFluidTank) slot ).getFluidStack() );
slot.slotClicked( this.mc.player.inventory.getItemStack(), btn );
return;
}
}
}
super.mouseClicked( xCoord, yCoord, btn );
}
@Override
protected boolean drawUpgrades()
{
return false;
}
@Override
public void updateSetting( IConfigManager manager, Enum settingName, Enum newValue )
{
}
}
@@ -19,50 +19,42 @@
package appeng.fluids.client.gui.widgets;
import appeng.client.gui.widgets.GuiCustomSlot;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketInventoryAction;
import appeng.helpers.InventoryAction;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.util.AEColor;
import appeng.client.gui.widgets.ITooltip;
import appeng.fluids.util.IAEFluidTank;
@SideOnly( Side.CLIENT )
public class GuiFluidTank extends GuiCustomSlot implements ITooltip
public class GuiFluidTank extends GuiButton implements ITooltip
{
private final IAEFluidTank tank;
private final int slot;
private final int width;
private final int height;
public GuiFluidTank( IAEFluidTank tank, int slot, int id, int x, int y, int w, int h )
{
super( id, x, y );
super( id, x, y, w, h, "" );
this.tank = tank;
this.slot = slot;
this.width = w;
this.height = h;
}
@Override
public void drawContent( Minecraft mc, int mouseX, int mouseY, float partialTicks )
public void drawButton( final Minecraft mc, final int mouseX, final int mouseY, final float partialTicks )
{
final IAEFluidStack fs = this.getFluidStack();
if( fs != null )
if( this.visible )
{
GlStateManager.disableBlend();
GlStateManager.disableLighting();
//drawRect( this.x, this.y, this.x + this.width, this.y + this.height, AEColor.GRAY.blackVariant | 0xFF000000 );
drawRect( this.x, this.y, this.x + this.width, this.y + this.height, AEColor.GRAY.blackVariant | 0xFF000000 );
final IAEFluidStack fluid = this.tank.getFluidInSlot( this.slot );
if( fluid != null && fluid.getStackSize() > 0 )
@@ -77,16 +69,17 @@ public class GuiFluidTank extends GuiCustomSlot implements ITooltip
TextureAtlasSprite sprite = mc.getTextureMapBlocks().getAtlasSprite( fluid.getFluid().getStill().toString() );
final int scaledHeight = (int) ( this.height * ( (float) fluid.getStackSize() / this.tank.getTankProperties()[this.slot].getCapacity() ) );
int iconHeightRemainder = scaledHeight % this.getHeight();
int iconHeightRemainder = scaledHeight % 16;
if( iconHeightRemainder > 0 )
{
this.drawTexturedModalRect( this.xPos(), this.yPos() + this.getHeight() - iconHeightRemainder, sprite, this.getWidth(), iconHeightRemainder );
this.drawTexturedModalRect( this.x, this.y + this.height - iconHeightRemainder, sprite, 16, iconHeightRemainder );
}
for( int i = 0; i < scaledHeight / this.getHeight(); i++ )
for( int i = 0; i < scaledHeight / 16; i++ )
{
this.drawTexturedModalRect( this.xPos(), this.yPos() + this.getHeight() - iconHeightRemainder - ( i + 1 ) * 16, sprite, this.getWidth(), this.getHeight() );
this.drawTexturedModalRect( this.x, this.y + this.height - iconHeightRemainder - ( i + 1 ) * 16, sprite, 16, 16 );
}
}
}
}
@@ -107,25 +100,25 @@ public class GuiFluidTank extends GuiCustomSlot implements ITooltip
@Override
public int xPos()
{
return this.x - 1;
return this.x - 2;
}
@Override
public int yPos()
{
return this.y - 1;
return this.y - 2;
}
@Override
public int getWidth()
{
return this.width;
return this.width + 4;
}
@Override
public int getHeight()
{
return this.height + 1;
return this.height + 4;
}
@Override
@@ -134,24 +127,4 @@ public class GuiFluidTank extends GuiCustomSlot implements ITooltip
return true;
}
public IAEFluidStack getFluidStack()
{
return this.tank.getFluidInSlot( this.slot );
}
@Override
public void slotClicked( ItemStack clickStack, final int mouseButton )
{
if( getFluidStack() != null )
{
NetworkHandler.instance().sendToServer( new PacketInventoryAction( InventoryAction.FILL_ITEM, slot, 0 ) );
}
else
{
NetworkHandler.instance().sendToServer( new PacketInventoryAction( InventoryAction.EMPTY_ITEM, slot, 0 ) );
}
}
}
@@ -19,17 +19,9 @@
package appeng.fluids.container;
import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.Map;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketTargetFluidStack;
import appeng.fluids.util.AEFluidStack;
import appeng.helpers.InventoryAction;
import appeng.util.IConfigManagerHost;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IContainerListener;
@@ -41,19 +33,12 @@ import appeng.fluids.helper.FluidSyncHelper;
import appeng.fluids.helper.IFluidInterfaceHost;
import appeng.fluids.util.IAEFluidTank;
import appeng.util.Platform;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
public class ContainerFluidInterface extends ContainerFluidConfigurable implements IConfigManagerHost
public class ContainerFluidInterface extends ContainerFluidConfigurable
{
private final DualityFluidInterface myDuality;
private final FluidSyncHelper tankSync;
private IConfigManagerHost gui;
// Holds the fluid the client wishes to extract, or null for insert
private IAEFluidStack clientRequestedTargetFluid = null;
public ContainerFluidInterface( final InventoryPlayer ip, final IFluidInterfaceHost te )
{
@@ -75,15 +60,6 @@ public class ContainerFluidInterface extends ContainerFluidConfigurable implemen
return this.myDuality.getConfig();
}
@Override
public void updateSetting( IConfigManager manager, Enum settingName, Enum newValue )
{
if( this.getGui() != null )
{
this.getGui().updateSetting( manager, settingName, newValue );
}
}
@Override
public void detectAndSendChanges()
{
@@ -121,126 +97,6 @@ public class ContainerFluidInterface extends ContainerFluidConfigurable implemen
this.tankSync.readPacket( fluids );
}
private IConfigManagerHost getGui()
{
return this.gui;
}
public void setGui( @Nonnull final IConfigManagerHost gui )
{
this.gui = gui;
}
public void doAction( EntityPlayerMP player, InventoryAction action, int slot, long id )
{
if( action != InventoryAction.FILL_ITEM && action != InventoryAction.EMPTY_ITEM )
{
super.doAction( player, action, slot, id );
return;
}
final ItemStack held = player.inventory.getItemStack();
ItemStack heldCopy = held.copy();
heldCopy.setCount( 1 );
IFluidHandlerItem fh = FluidUtil.getFluidHandler( heldCopy );
if( fh == null )
{
// only fluid handlers items
return;
}
if( action == InventoryAction.FILL_ITEM && this.clientRequestedTargetFluid != null )
{
final IAEFluidStack stack = this.clientRequestedTargetFluid.copy();
// Check how much we can store in the item
stack.setStackSize( Integer.MAX_VALUE );
int amountAllowed = fh.fill( stack.getFluidStack(), false );
int heldAmount = held.getCount();
for( int i = 0; i < heldAmount; i++ )
{
ItemStack copiedFluidContainer = held.copy();
copiedFluidContainer.setCount( 1 );
fh = FluidUtil.getFluidHandler( copiedFluidContainer );
FluidStack extractableFluid = this.myDuality.getTanks().drain( stack.setStackSize( amountAllowed ).getFluidStack(), false );
if( extractableFluid == null || extractableFluid.amount == 0 )
{
break;
}
int fillableAmount = fh.fill( extractableFluid, false );
if( fillableAmount > 0 )
{
FluidStack extractedFluid = this.myDuality.getTanks().drain( extractableFluid, true );
fh.fill( extractedFluid, true );
}
if( held.getCount() == 1 )
{
player.inventory.setItemStack( fh.getContainer() );
}
else
{
player.inventory.getItemStack().shrink( 1 );
if( !player.inventory.addItemStackToInventory( fh.getContainer() ) )
{
player.dropItem( fh.getContainer(), false );
}
}
}
}
else if( action == InventoryAction.EMPTY_ITEM )
{
int heldAmount = held.getCount();
for( int i = 0; i < heldAmount; i++ )
{
ItemStack copiedFluidContainer = held.copy();
copiedFluidContainer.setCount( 1 );
fh = FluidUtil.getFluidHandler( copiedFluidContainer );
FluidStack drainable = fh.drain( this.myDuality.getTanks().getTankProperties()[slot].getCapacity(), false );
if( drainable != null )
{
fh.drain( drainable, true );
this.myDuality.getTanks().fill( drainable, true );
}
if( held.getCount() == 1 )
{
player.inventory.setItemStack( fh.getContainer() );
}
else
{
player.inventory.getItemStack().shrink( 1 );
if( !player.inventory.addItemStackToInventory( fh.getContainer() ) )
{
player.dropItem( fh.getContainer(), false );
}
}
}
}
this.updateHeld( player );
}
public void setTargetStack( final IAEFluidStack stack )
{
if( Platform.isClient() )
{
if( stack == null && this.clientRequestedTargetFluid == null )
{
return;
}
if( stack != null && this.clientRequestedTargetFluid != null && stack.getFluidStack().isFluidEqual( this.clientRequestedTargetFluid.getFluidStack() ) )
{
return;
}
NetworkHandler.instance().sendToServer( new PacketTargetFluidStack( (AEFluidStack) stack ) );
}
this.clientRequestedTargetFluid = stack == null ? null : stack.copy();
}
@Override
protected boolean supportCapacity()
{
@@ -19,15 +19,15 @@
package appeng.fluids.parts;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Settings;
import appeng.api.config.StorageFilter;
import appeng.api.storage.data.IAEItemStack;
import appeng.me.GridAccessException;
import appeng.util.inv.ItemSlot;
import net.minecraft.item.ItemStack;
import appeng.parts.misc.PartStorageBus;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fluids.capability.IFluidTankProperties;
@@ -63,20 +63,17 @@ public class FluidHandlerAdapter implements IMEInventory<IAEFluidStack>, IBaseMo
private final IGridProxyable proxyable;
private final FluidHandlerAdapter.InventoryCache cache;
private StorageFilter mode;
private AccessRestriction access;
FluidHandlerAdapter( IFluidHandler fluidHandler, IGridProxyable proxy )
{
this.fluidHandler = fluidHandler;
this.proxyable = proxy;
if( this.proxyable instanceof PartFluidStorageBus )
if( this.proxyable instanceof PartStorageBus )
{
PartFluidStorageBus partFluidStorageBus = (PartFluidStorageBus) this.proxyable;
this.mode = ( (StorageFilter) partFluidStorageBus.getConfigManager().getSetting( Settings.STORAGE_FILTER ) );
this.access = ( (AccessRestriction) partFluidStorageBus.getConfigManager().getSetting( Settings.ACCESS ) );
PartStorageBus partStorageBus = (PartStorageBus) this.proxyable;
this.mode = ( (StorageFilter) partStorageBus.getConfigManager().getSetting( Settings.STORAGE_FILTER ) );
}
this.cache = new FluidHandlerAdapter.InventoryCache( this.fluidHandler, this.mode );
this.cache.update();
this.cache = new FluidHandlerAdapter.InventoryCache( this.fluidHandler, this.mode);
}
@Override
@@ -95,17 +92,9 @@ public class FluidHandlerAdapter implements IMEInventory<IAEFluidStack>, IBaseMo
if( type == Actionable.MODULATE )
{
IAEFluidStack added = input.copy().setStackSize( input.getStackSize() - remaining );
this.cache.currentlyCached.add( added );
this.postDifference( Collections.singletonList( added ) );
try
{
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
}
catch( GridAccessException ex )
{
// meh
}
this.cache
.currentlyCached
.add( input.copy().setStackSize( wasFillled ));
}
fluidStack.amount = remaining;
@@ -130,19 +119,10 @@ public class FluidHandlerAdapter implements IMEInventory<IAEFluidStack>, IBaseMo
IAEFluidStack gatheredAEFluidstack = AEFluidStack.fromFluidStack( gathered );
if( mode == Actionable.MODULATE )
{
IAEFluidStack cachedStack = this.cache.currentlyCached.findPrecise( request );
if( cachedStack != null )
IAEFluidStack e = this.cache.currentlyCached.findPrecise( gatheredAEFluidstack );
if (e != null)
{
cachedStack.decStackSize( gatheredAEFluidstack.getStackSize() );
this.postDifference( Collections.singletonList( gatheredAEFluidstack.copy().setStackSize( -gatheredAEFluidstack.getStackSize() ) ) );
}
try
{
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
}
catch( GridAccessException ex )
{
// meh
e.decStackSize( gathered.amount );
}
}
return gatheredAEFluidstack;
@@ -152,7 +132,7 @@ public class FluidHandlerAdapter implements IMEInventory<IAEFluidStack>, IBaseMo
public TickRateModulation onTick()
{
List<IAEFluidStack> changes = this.cache.update();
if( !changes.isEmpty() && access.hasPermission( AccessRestriction.READ ) )
if( !changes.isEmpty() )
{
this.postDifference( changes );
return TickRateModulation.URGENT;
@@ -217,6 +197,7 @@ public class FluidHandlerAdapter implements IMEInventory<IAEFluidStack>, IBaseMo
private final StorageFilter mode;
IItemList<IAEFluidStack> currentlyCached = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
public InventoryCache( IFluidHandler fluidHandler, StorageFilter mode )
{
this.mode = mode;
@@ -204,7 +204,7 @@ public class PartFluidFormationPlane extends PartAbstractFormationPlane<IAEFluid
@Override
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
{
if( channel == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) )
if( this.getProxy().isActive() && channel == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) )
{
final List<IMEInventoryHandler> handler = new ArrayList<>( 1 );
handler.add( this.myHandler );
@@ -5,7 +5,6 @@ package appeng.fluids.parts;
import java.util.Random;
import appeng.api.networking.events.MENetworkChannelChanged;
import appeng.api.storage.data.IItemList;
import appeng.fluids.helper.IConfigurableFluidInventory;
import appeng.me.cache.NetworkMonitor;
import net.minecraft.entity.player.EntityPlayer;
@@ -114,7 +113,7 @@ public class PartFluidLevelEmitter extends PartUpgradeable implements IStackWatc
}
@Override
public void onStackChange( IItemList<?> o, IAEStack<?> fullStack, IAEStack<?> diffStack, IActionSource src, IStorageChannel<?> chan )
public void onStackChange( IAEStack<?> diffStack, IStorageChannel<?> chan )
{
if( chan == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) && diffStack.equals( this.config.getFluidInSlot( 0 ) ) )
{
@@ -26,7 +26,6 @@ import java.util.Objects;
import javax.annotation.Nonnull;
import appeng.fluids.helper.IConfigurableFluidInventory;
import appeng.util.ConfigManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -168,28 +167,11 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
final boolean fullReset = this.resetCacheLogic == 2;
this.resetCacheLogic = 0;
final MEInventoryHandler<IAEFluidStack> in = this.getInternalHandler();
final IMEInventory<IAEFluidStack> in = this.getInternalHandler();
IItemList<IAEFluidStack> before = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
boolean denyRead = false;
if( in != null )
{
if( accessChanged )
{
AccessRestriction currentAccess = (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getSetting( Settings.ACCESS );
AccessRestriction oldAccess = (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getOldSetting( Settings.ACCESS );
if( oldAccess.hasPermission( AccessRestriction.READ ) && !currentAccess.hasPermission( AccessRestriction.READ ) )
{
denyRead = true;
}
in.setBaseAccess( oldAccess );
before = in.getAvailableItems( before );
in.setBaseAccess( currentAccess );
accessChanged = false;
}
else
{
before = in.getAvailableItems( before );
}
before = in.getAvailableItems( before );
}
this.cached = false;
@@ -198,17 +180,15 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
this.handlerHash = 0;
}
final MEInventoryHandler<IAEFluidStack> out = this.getInternalHandler();
final IMEInventory<IAEFluidStack> out = this.getInternalHandler();
if( in != out || denyRead )
if( in != out )
{
IItemList<IAEFluidStack> after = AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ).createList();
if( out != null && !denyRead )
if( out != null )
{
after = out.getAvailableItems( after );
}
Platform.postListChanges( before, after, this, this.source );
}
}
@@ -284,14 +264,6 @@ public class PartFluidStorageBus extends PartSharedStorageBus implements IMEMoni
@Override
public void postChange( final IBaseMonitor<IAEFluidStack> monitor, final Iterable<IAEFluidStack> change, final IActionSource source )
{
if( this.source.machine().map( machine -> machine == this ).orElse( false ) && monitor != null )
{
AccessRestriction currentAccess = (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getSetting( Settings.ACCESS );
if( !currentAccess.hasPermission( AccessRestriction.READ ) )
{
return;
}
}
try
{
if( this.getProxy().isActive() )
@@ -24,12 +24,9 @@ import java.util.*;
import javax.annotation.Nullable;
import appeng.api.definitions.IItemDefinition;
import appeng.api.networking.crafting.*;
import appeng.integration.modules.gregtech.GTCEInventoryAdaptor;
import appeng.me.cache.CraftingGridCache;
import appeng.util.*;
import appeng.util.inv.*;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableSet;
import de.ellpeck.actuallyadditions.api.tile.IPhantomTile;
@@ -68,6 +65,10 @@ import appeng.api.implementations.tiles.ICraftingMachine;
import appeng.api.networking.GridFlags;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingLink;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.crafting.ICraftingProvider;
import appeng.api.networking.crafting.ICraftingProviderHelper;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.events.MENetworkCraftingPatternChange;
import appeng.api.networking.security.IActionHost;
@@ -109,6 +110,7 @@ import static gregtech.api.block.machines.BlockMachine.getMetaTileEntity;
public class DualityInterface implements IGridTickable, IStorageMonitorable, IInventoryDestination, IAEAppEngInventory, IConfigManagerHost, ICraftingProvider, IUpgradeableHost
{
private int[] failedCraftTriesSlot = {0,0,0,0,0,0,0,0,0};
public static final int NUMBER_OF_STORAGE_SLOTS = 9;
public static final int NUMBER_OF_CONFIG_SLOTS = 9;
@@ -929,7 +931,17 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn
{
if( this.getInstalledUpgrades( Upgrades.CRAFTING ) > 0 && itemStack != null )
{
return this.craftingTracker.handleCrafting( x, itemStack.getStackSize(), itemStack, d, this.iHost.getTileEntity().getWorld(), this.gridProxy.getGrid(), this.gridProxy.getCrafting(), this.mySource );
if (this.failedCraftTriesSlot[x] <= 0)
{
boolean crafted = this.craftingTracker.handleCrafting( x, itemStack.getStackSize(), itemStack, d, this.iHost.getTileEntity().getWorld(),
this.gridProxy.getGrid(), this.gridProxy.getCrafting(), this.mySource );
if (crafted) this.failedCraftTriesSlot[x] = 0;
else{
this.failedCraftTriesSlot[x] += 2;
}
}
this.failedCraftTriesSlot[x] -= 1;
}
}
catch( final GridAccessException e )
@@ -22,9 +22,6 @@ package appeng.helpers;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import appeng.api.networking.crafting.*;
import appeng.me.cache.CraftingGridCache;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableSet;
import net.minecraft.nbt.NBTTagCompound;
@@ -32,6 +29,10 @@ import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.networking.IGrid;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingJob;
import appeng.api.networking.crafting.ICraftingLink;
import appeng.api.networking.crafting.ICraftingRequester;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.data.IAEItemStack;
import appeng.util.InventoryAdaptor;
@@ -131,17 +132,6 @@ public class MultiCraftingTracker
final IAEItemStack aisC = ais.copy();
aisC.setStackSize( itemToCraft );
CraftingGridCache cgc = (CraftingGridCache) cg;
ImmutableCollection<ICraftingPatternDetails> cl = cgc.getCraftingFor( aisC, null, x, w );
for( ICraftingPatternDetails craftingPatternDetails : cl )
{
if( cgc.getPatternStatusManager().containsIncompletablePattern( craftingPatternDetails ) )
{
return false;
}
}
this.setJob( x, cg.beginCraftingJob( w, g, mySrc, aisC, null ) );
}
}
+12 -7
View File
@@ -187,15 +187,20 @@ public class TickHandler
if( ev.type == Type.WORLD && ev.phase == Phase.END )
{
final WorldTickEvent wte = (WorldTickEvent) ev;
synchronized ( this.craftingJobs )
synchronized( this.craftingJobs )
{
final Collection<CraftingJob> jobSet = this.craftingJobs.get( wte.world );
if (!jobSet.isEmpty()) {
final int jobSize = jobSet.size();
final int microSecondsPerTick = AEConfig.instance().getCraftingCalculationTimePerTick() * 1000;
final int simTime = Math.max(1, microSecondsPerTick / jobSize);
jobSet.removeIf( cj -> !cj.simulateFor( simTime ) );
if( !jobSet.isEmpty() )
{
final Iterator<CraftingJob> i = jobSet.iterator();
while( i.hasNext() )
{
final CraftingJob cj = i.next();
if( !cj.simulateFor() )
{
i.remove();
}
}
}
}
}
+13 -28
View File
@@ -30,19 +30,22 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;
import appeng.me.helpers.PatternStatusManager;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import it.unimi.dsi.fastutil.objects.*;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectRBTreeSet;
import it.unimi.dsi.fastutil.objects.ObjectSet;
import net.minecraft.world.World;
import appeng.api.AEApi;
@@ -267,17 +270,20 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
// coalesce change events during a grid traversal to a single rebuild
if (pauseRebuilds != 0)
{
rebuildNeeded.add( this );
rebuildNeeded.add(this);
return;
}
final Object2ObjectMap<IAEItemStack, ImmutableList<ICraftingPatternDetails>> oldItems = new Object2ObjectOpenHashMap<>( this.craftableItems );
final Object2ObjectMap<IAEItemStack, ImmutableList<ICraftingPatternDetails>> oldItems = this.craftableItems;
// erase list.
this.craftingMethods.clear();
this.craftableItems.clear();
this.emitableItems.clear();
( (GridStorageCache) this.storageGrid ).clearPatternStatus();
// update the stuff that was in the list...
this.storageGrid.postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), oldItems.keySet(),
new BaseActionSource() );
// re-create list..
for( final ICraftingProvider provider : this.craftingProviders )
@@ -313,23 +319,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
this.craftableItems.put( e.getKey(), ImmutableList.copyOf( e.getValue() ) );
}
Object2ObjectMap<IAEItemStack, ImmutableList<ICraftingPatternDetails>> craftablesChanged = new Object2ObjectArrayMap<>();
ObjectSet<Entry<IAEItemStack, ImmutableList<ICraftingPatternDetails>>> i = oldItems.entrySet();
for ( Entry<IAEItemStack, ImmutableList<ICraftingPatternDetails>> ais : i) {
if (!this.craftableItems.containsKey( ais.getKey() )) {
craftablesChanged.put( ais.getKey().setCraftable( false ), ais.getValue() );
}
}
ObjectSet<Entry<IAEItemStack, ImmutableList<ICraftingPatternDetails>>> j = this.craftableItems.entrySet();
for ( Entry<IAEItemStack, ImmutableList<ICraftingPatternDetails>> ais : j) {
if (!oldItems.containsKey( ais )){
craftablesChanged.put( ais.getKey().setCraftable( true ), ais.getValue() );
}
}
this.storageGrid.postCraftablesChanges( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), craftablesChanged.keySet(),
this.storageGrid.postAlterationOfStoredItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ), this.craftableItems.keySet(),
new BaseActionSource() );
}
@@ -649,7 +639,7 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
public boolean hasCpu( final ICraftingCPU cpu )
{
if( cpu instanceof CraftingCPUCluster )
if (cpu instanceof CraftingCPUCluster)
{
return this.craftingCPUClusters.contains( (CraftingCPUCluster) cpu );
}
@@ -661,11 +651,6 @@ public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper
return this.interestManager;
}
public PatternStatusManager getPatternStatusManager()
{
return ( (GridStorageCache) this.storageGrid ).getPatternStatusManager();
}
private static class ActiveCpuIterator implements Iterator<ICraftingCPU>
{
+50 -98
View File
@@ -19,10 +19,21 @@
package appeng.me.cache;
import java.util.*;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.NavigableSet;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import com.google.common.base.Preconditions;
import com.google.common.collect.*;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
import com.google.common.collect.Sets;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
@@ -70,7 +81,7 @@ public class EnergyGridCache implements IEnergyGrid
// Should only be modified from the add/remove methods below to guard against
// concurrent modifications
private final double averageLength = 40.0;
private final Multimap<Integer,IAEPowerStorage> providers = HashMultimap.create();
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.
@@ -78,7 +89,7 @@ public class EnergyGridCache implements IEnergyGrid
// Should only be modified from the add/remove methods below to guard against
// concurrent modifications
private final Multimap<Integer,IAEPowerStorage> requesters = HashMultimap.create();
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.
@@ -115,16 +126,16 @@ public class EnergyGridCache implements IEnergyGrid
private double lastStoredPower = -1;
private final GridPowerStorage localStorage = new GridPowerStorage();
private Set<IAEPowerStorage> providersToRemove = new HashSet<>();
private Set<IAEPowerStorage> requestersToRemove = new HashSet<>();
private Set<IAEPowerStorage> providerToRemove = new HashSet<>();
private Set<IAEPowerStorage> requesterToRemove = new HashSet<>();
private Set<IAEPowerStorage> providersToAdd = new HashSet<>();
private Set<IAEPowerStorage> requestersToAdd = new HashSet<>();
private Set<IAEPowerStorage> requesterToAdd = new HashSet<>();
public EnergyGridCache( final IGrid g )
{
this.myGrid = g;
this.requesters.put( 0, this.localStorage );
this.providers.put( 1, this.localStorage );
this.requesters.add( this.localStorage );
this.providers.add( this.localStorage );
}
@MENetworkEventSubscribe
@@ -176,7 +187,7 @@ public class EnergyGridCache implements IEnergyGrid
}
else
{
this.requestersToAdd.add( ev.storage );
this.requesterToAdd.add( ev.storage );
}
}
break;
@@ -220,7 +231,7 @@ public class EnergyGridCache implements IEnergyGrid
if( this.drainPerTick > 0.0001 )
{
final double drained = this.extractAEPower( this.getIdlePowerUsage(), Actionable.MODULATE, PowerMultiplier.CONFIG );
currentlyHasPower = drained >= this.drainPerTick - 0.001;
currentlyHasPower = drained >= this.drainPerTick - 0.001 && this.getStoredPower() > 0;
}
else
{
@@ -307,7 +318,7 @@ public class EnergyGridCache implements IEnergyGrid
{
this.availableTicksSinceUpdate = 0;
this.globalAvailablePower = 0;
for( final IAEPowerStorage p : this.providers.values() )
for( final IAEPowerStorage p : this.providers )
{
this.globalAvailablePower += p.getAECurrentPower();
}
@@ -324,19 +335,10 @@ public class EnergyGridCache implements IEnergyGrid
{
double extractedPower = 0;
providersToAdd.forEach( provider -> {
if( provider instanceof GridPowerStorage )
{
providers.put( 1, provider );
}
else
{
providers.put( 0, provider );
}
} );
this.providers.addAll( providersToAdd );
providersToAdd.clear();
final Iterator<IAEPowerStorage> it = this.providers.values().iterator();
final Iterator<IAEPowerStorage> it = this.providers.iterator();
ongoingExtractOperation = true;
try
@@ -356,17 +358,8 @@ public class EnergyGridCache implements IEnergyGrid
}
} finally
{
providersToRemove.forEach( provider -> {
if( provider instanceof GridPowerStorage )
{
providers.remove( 1, provider );
}
else
{
providers.remove( 0, provider );
}
} );
this.providersToRemove.clear();
providers.removeIf( p -> providerToRemove.contains( p ) );
this.providerToRemove.clear();
ongoingExtractOperation = false;
}
@@ -391,19 +384,10 @@ public class EnergyGridCache implements IEnergyGrid
{
final double originalAmount = amt;
requestersToAdd.forEach( requester -> {
if( requester instanceof GridPowerStorage )
{
requesters.put( 0, requester );
}
else
{
requesters.put( 1, requester );
}
} );
requestersToAdd.clear();
this.requesters.addAll( requesterToAdd );
requesterToAdd.clear();
final Iterator<IAEPowerStorage> it = this.requesters.values().iterator();
final Iterator<IAEPowerStorage> it = this.requesters.iterator();
ongoingInjectOperation = true;
try
@@ -421,17 +405,8 @@ public class EnergyGridCache implements IEnergyGrid
}
} finally
{
requestersToRemove.forEach( requester -> {
if( requester instanceof GridPowerStorage )
{
requesters.remove( 0, requester );
}
else
{
requesters.remove( 1, requester );
}
} );
this.requestersToRemove.clear();
requesters.removeIf( r -> requesterToRemove.contains( r ) );
this.requesterToRemove.clear();
ongoingInjectOperation = false;
}
@@ -450,7 +425,7 @@ public class EnergyGridCache implements IEnergyGrid
{
double required = 0;
final Iterator<IAEPowerStorage> it = this.requesters.values().iterator();
final Iterator<IAEPowerStorage> it = this.requesters.iterator();
while( required < maxRequired && it.hasNext() )
{
final IAEPowerStorage node = it.next();
@@ -591,7 +566,7 @@ public class EnergyGridCache implements IEnergyGrid
}
else
{
this.providersToRemove.add( ps );
this.providerToRemove.add( ps );
}
if( !ongoingInjectOperation )
{
@@ -599,7 +574,7 @@ public class EnergyGridCache implements IEnergyGrid
}
else
{
this.requestersToRemove.add( ps );
this.requesterToRemove.add( ps );
}
}
}
@@ -619,55 +594,28 @@ public class EnergyGridCache implements IEnergyGrid
private void addRequester(IAEPowerStorage requester) {
Preconditions.checkState(!ongoingInjectOperation,
"Cannot modify energy requesters while energy is being injected.");
if( requester instanceof GridPowerStorage )
{
requesters.put( 0, requester );
}
else
{
requesters.put( 1, requester );
}
this.requesters.add(requester);
}
private void removeRequester(IAEPowerStorage requester) {
Preconditions.checkState(!ongoingInjectOperation,
"Cannot modify energy requesters while energy is being injected.");
if( requester instanceof GridPowerStorage )
{
requesters.remove( 0, requester );
}
else
{
requesters.remove( 1, requester );
}
this.requesters.remove(requester);
}
private void addProvider(IAEPowerStorage provider) {
Preconditions.checkState(!ongoingExtractOperation,
"Cannot modify energy providers while energy is being extracted.");
if( provider instanceof GridPowerStorage )
{
providers.put( 1, provider );
}
else
{
providers.put( 0, provider );
}
this.providers.add(provider);
}
private void removeProvider(IAEPowerStorage provider)
{
Preconditions.checkState( !ongoingExtractOperation, "Cannot modify energy providers while energy is being extracted." );
if( provider instanceof GridPowerStorage )
{
providers.remove( 1, provider );
}
else
{
providers.remove( 0, provider );
}
private void removeProvider(IAEPowerStorage provider) {
Preconditions.checkState(!ongoingExtractOperation,
"Cannot modify energy providers while energy is being extracted.");
this.providers.remove(provider);
}
@Override
public void addNode( final IGridNode node, final IGridHost machine )
{
@@ -717,7 +665,7 @@ public class EnergyGridCache implements IEnergyGrid
}
else
{
this.requestersToAdd.add( ps );
this.requesterToAdd.add( ps );
}
}
}
@@ -840,8 +788,12 @@ public class EnergyGridCache implements IEnergyGrid
if( this.stored < 0.01 )
{
EnergyGridCache.this.ticksSinceHasPowerChange = 0;
EnergyGridCache.this.publicPowerState( false, EnergyGridCache.this.myGrid );
refreshPower();
if (globalAvailablePower < MAX_BUFFER_STORAGE - 0.001)
{
EnergyGridCache.this.ticksSinceHasPowerChange = 0;
EnergyGridCache.this.publicPowerState( false, EnergyGridCache.this.myGrid );
}
}
}
}
+2 -25
View File
@@ -26,10 +26,7 @@ import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.me.helpers.PatternStatusManager;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.SetMultimap;
import appeng.api.AEApi;
@@ -68,10 +65,6 @@ public class GridStorageCache implements IStorageGrid
private final HashSet<ICellProvider> inactiveCellProviders = new HashSet<>();
private final SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create();
private final GenericInterestManager<ItemWatcher> interestManager = new GenericInterestManager<>( this.interests );
private final Multimap<ICraftingPatternDetails, IAEStack> patternDetails2IAEStackMultimap = HashMultimap.create();
private final Multimap<IAEStack, ICraftingPatternDetails> iaeStack2PatternDetailsMultimap = HashMultimap.create();
private final PatternStatusManager patternStatusManager = new PatternStatusManager( this.patternDetails2IAEStackMultimap, this.iaeStack2PatternDetailsMultimap );
private final HashMap<IGridNode, IStackWatcher> watchers = new HashMap<>();
private Map<IStorageChannel<? extends IAEStack>, NetworkInventoryHandler<?>> storageNetworks;
private Map<IStorageChannel<? extends IAEStack>, NetworkMonitor<?>> storageMonitors;
@@ -255,6 +248,8 @@ public class GridStorageCache implements IStorageGrid
}
}
this.storageMonitors.forEach( ( channel, monitor ) -> monitor.forceUpdate() );
tracker.applyChanges();
}
@@ -286,12 +281,6 @@ public class GridStorageCache implements IStorageGrid
this.storageMonitors.get( chan ).postChange( true, (Iterable) input, src );
}
@Override
public void postCraftablesChanges( IStorageChannel<?> chan, Iterable<? extends IAEStack<?>> input, IActionSource src )
{
this.storageMonitors.get( chan ).updateCraftables( (Iterable) input, src );
}
@Override
public void registerCellProvider( final ICellProvider provider )
{
@@ -311,18 +300,6 @@ public class GridStorageCache implements IStorageGrid
return this.interestManager;
}
public PatternStatusManager getPatternStatusManager()
{
return this.patternStatusManager;
}
public void clearPatternStatus()
{
System.out.println( "reseting pattern status due to pattern changes" );
this.patternDetails2IAEStackMultimap.clear();
this.iaeStack2PatternDetailsMultimap.clear();
}
IGrid getGrid()
{
return this.myGrid;
+128 -100
View File
@@ -19,35 +19,38 @@
package appeng.me.cache;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Deque;
import java.util.Iterator;
import java.util.Map.Entry;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import appeng.api.AEApi;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Queues;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.events.MENetworkStorageEvent;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.IMEInventoryHandler;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.me.storage.ItemWatcher;
import com.google.common.collect.Queues;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import java.util.Collection;
import java.util.Deque;
import java.util.Iterator;
import java.util.Map.Entry;
public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
{
@@ -64,6 +67,7 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
private final Object2ObjectMap<IMEMonitorHandlerReceiver<T>, Object> listeners;
private boolean sendEvent = false;
private boolean hasChanged = false;
@Nonnegative
private int localDepthSemaphore = 0;
private long gridItemCount;
@@ -92,7 +96,21 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
@Override
public T extractItems( final T request, final Actionable mode, final IActionSource src )
{
return this.getHandler().extractItems( request, mode, src );
if( mode == Actionable.SIMULATE )
{
return this.getHandler().extractItems( request, mode, src );
}
this.localDepthSemaphore++;
final T leftover = this.getHandler().extractItems( request, mode, src );
this.localDepthSemaphore--;
if( this.localDepthSemaphore == 0 )
{
this.monitorDifference( request.copy(), leftover, true, src );
}
return leftover;
}
@Override
@@ -155,13 +173,34 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
@Override
public IItemList<T> getStorageList()
{
if( hasChanged )
{
hasChanged = false;
this.cachedList.resetStatus();
return this.getAvailableItems( this.cachedList );
}
return this.cachedList;
}
@Override
public T injectItems( final T input, final Actionable mode, final IActionSource src )
{
return this.getHandler().injectItems( input, mode, src );
if( mode == Actionable.SIMULATE )
{
return this.getHandler().injectItems( input, mode, src );
}
this.localDepthSemaphore++;
final T leftover = this.getHandler().injectItems( input, mode, src );
this.localDepthSemaphore--;
if( this.localDepthSemaphore == 0 )
{
this.monitorDifference( input.copy(), leftover, false, src );
}
return leftover;
}
@Override
@@ -193,15 +232,37 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
return this.listeners.entrySet().iterator();
}
private T monitorDifference( final IAEStack<T> original, final T leftOvers, final boolean extraction, final IActionSource src )
{
final T diff = original.copy();
if( extraction )
{
diff.setStackSize( leftOvers == null ? 0 : -leftOvers.getStackSize() );
}
else if( leftOvers != null )
{
diff.decStackSize( leftOvers.getStackSize() );
}
if( diff.getStackSize() != 0 )
{
this.postChangesToListeners( ImmutableList.of( diff ), src );
}
return leftOvers;
}
private void notifyListenersOfChange( final Iterable<T> diff, final IActionSource src )
{
this.hasChanged = true;
final Iterator<Entry<IMEMonitorHandlerReceiver<T>, Object>> i = this.getListeners();
while( i.hasNext() )
{
final Entry<IMEMonitorHandlerReceiver<T>, Object> o = i.next();
final IMEMonitorHandlerReceiver<T> receiver = o.getKey();
if( receiver.isValid( o.getValue() ) )
if( receiver.isValid( o.getValue() ) && receiver.hasListeners() )
{
receiver.postChange( this, diff, src );
}
@@ -212,40 +273,35 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
}
}
protected void updateCraftables( Iterable<T> input, IActionSource src )
private void postChangesToListeners( final Iterable<T> changes, final IActionSource src )
{
for( final T changedItem : input )
{
if (changedItem.isCraftable()) {
this.cachedList.add( changedItem.copy().setCraftable( true ) );
}
else
{
this.cachedList.findPrecise( changedItem ).setCraftable( false );
}
}
this.postChange( true, changes, src );
}
protected void postChange( final boolean add, final Iterable<T> changes, final IActionSource src )
{
if( GLOBAL_DEPTH.contains( this ) )
if( this.localDepthSemaphore > 0 || GLOBAL_DEPTH.contains( this ) )
{
return;
}
GLOBAL_DEPTH.push( this );
this.localDepthSemaphore++;
this.sendEvent = true;
for( final T changedItem : changes )
for ( final T changedItem : changes )
{
T difference = changedItem;
if( !add && changedItem != null )
{
changedItem.setStackSize( -changedItem.getStackSize() );
difference = changedItem.copy();
difference.setStackSize( -changedItem.getStackSize() );
}
incGridCurrentCount( changedItem.getStackSize() );
this.cachedList.add( changedItem );
incGridCurrentCount( difference.getStackSize() );
this.cachedList.add( difference );
if( this.myGridCache.getInterestManager().containsKey( changedItem ) )
{
@@ -253,90 +309,22 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
if( !list.isEmpty() )
{
IAEStack<T> fullStack = this.getStorageList().findPrecise( changedItem );
if( fullStack == null )
{
fullStack = changedItem.copy();
fullStack.setStackSize( 0 );
}
this.myGridCache.getInterestManager().enableTransactions();
for( final ItemWatcher iw : list )
{
iw.getHost().onStackChange( this.getStorageList(), fullStack, changedItem, src, this.getChannel() );
iw.getHost().onStackChange( difference, this.getChannel() );
}
this.myGridCache.getInterestManager().disableTransactions();
}
}
if( changedItem instanceof IAEItemStack )
{
if( this.myGridCache.getPatternStatusManager().containsMissingIAEStack( changedItem ) )
{
this.myGridCache.getPatternStatusManager().enableTransactions();
for( ICraftingPatternDetails craftingPatternDetails : this.myGridCache.getPatternStatusManager().getIncompletablePattern( changedItem ) )
{
for( IAEStack stack : this.myGridCache.getPatternStatusManager().getMissingIAEStack( craftingPatternDetails ) )
{
if( craftingPatternDetails.canSubstitute() )
{
if( ( (IAEItemStack) stack ).getItem().isDamageable() )
{
if( ( (IAEStack) changedItem ).fuzzyComparison( stack, FuzzyMode.IGNORE_ALL ) )
{
if( changedItem.getStackSize() > 0 )
{
this.myGridCache.getPatternStatusManager().remove( craftingPatternDetails, stack );
}
}
}
else
{
if( ( (IAEItemStack) stack ).sameOre( (IAEItemStack) changedItem ) )
{
if( changedItem.getStackSize() > 0 )
{
if( changedItem.getStackSize() >= stack.getStackSize() )
{
this.myGridCache.getPatternStatusManager().remove( craftingPatternDetails, stack );
}
else
{
stack.decStackSize( changedItem.getStackSize() );
}
}
}
}
}
else if( stack.equals( changedItem ) )
{
if( changedItem.getStackSize() > 0 )
{
if( changedItem.getStackSize() >= stack.getStackSize() )
{
this.myGridCache.getPatternStatusManager().remove( craftingPatternDetails, stack );
}
else
{
stack.decStackSize( changedItem.getStackSize() );
}
}
}
}
}
this.myGridCache.getPatternStatusManager().disableTransactions();
}
}
}
this.notifyListenersOfChange( changes, src );
final NetworkMonitor<?> last = GLOBAL_DEPTH.pop();
this.localDepthSemaphore--;
if( last != this )
{
@@ -344,6 +332,46 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
}
}
void forceUpdate()
{
this.hasChanged = true;
//when the grid comes back online, reset the count to 0 so
//it reflects the correct amount after the changes are accounted for
if( myChannel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
{
gridItemCount = 0;
for( IAEItemStack iaeItemStack : (Iterable<IAEItemStack>) getStorageList() )
{
gridItemCount += iaeItemStack.getStackSize();
}
}
else if( myChannel == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) )
{
gridFluidCount = 0;
for( IAEFluidStack iaeFluidStack : (Iterable<IAEFluidStack>) getStorageList() )
{
gridFluidCount += iaeFluidStack.getStackSize();
}
}
final Iterator<Entry<IMEMonitorHandlerReceiver<T>, Object>> i = this.getListeners();
while ( i.hasNext() )
{
final Entry<IMEMonitorHandlerReceiver<T>, Object> o = i.next();
final IMEMonitorHandlerReceiver<T> receiver = o.getKey();
if( receiver.isValid( o.getValue() ) )
{
receiver.onListUpdate();
}
else
{
i.remove();
}
}
}
void onTick()
{
if( this.sendEvent )
@@ -1,166 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* 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.me.helpers;
import appeng.api.config.FuzzyMode;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import com.google.common.collect.Multimap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class PatternStatusManager
{
private final Multimap<ICraftingPatternDetails, IAEStack> patternDetailsIAEStackMultimap;
private final Multimap<IAEStack, ICraftingPatternDetails> iaeStackPatternDetailsMultimap;
private List<SavedTransactions> transactions = null;
private int transDepth = 0;
public PatternStatusManager( final Multimap<ICraftingPatternDetails, IAEStack> interests, final Multimap<IAEStack, ICraftingPatternDetails> interested )
{
this.patternDetailsIAEStackMultimap = interests;
this.iaeStackPatternDetailsMultimap = interested;
}
public void enableTransactions()
{
if( this.transDepth == 0 )
{
this.transactions = new ArrayList<>();
}
this.transDepth++;
}
public void disableTransactions()
{
this.transDepth--;
if( this.transDepth == 0 )
{
final List<SavedTransactions> myActions = this.transactions;
this.transactions = null;
for( final SavedTransactions t : myActions )
{
if( t.put )
{
this.put( t.patternDetails, t.stack );
}
else
{
this.remove( t.patternDetails, t.stack );
}
}
}
}
public boolean put( final ICraftingPatternDetails craftingPatternDetails, final IAEStack debtStack )
{
if( this.transactions != null )
{
this.transactions.add( new SavedTransactions( true, craftingPatternDetails, debtStack ) );
return true;
}
else
{
this.iaeStackPatternDetailsMultimap.put( debtStack, craftingPatternDetails );
return this.patternDetailsIAEStackMultimap.put( craftingPatternDetails, debtStack );
}
}
public boolean remove( final ICraftingPatternDetails craftingPatternDetails, final IAEStack debtStack )
{
if( this.transactions != null )
{
this.transactions.add( new SavedTransactions( false, craftingPatternDetails, debtStack ) );
return true;
}
else
{
this.iaeStackPatternDetailsMultimap.remove( debtStack, craftingPatternDetails );
return this.patternDetailsIAEStackMultimap.remove( craftingPatternDetails, debtStack );
}
}
public boolean containsIncompletablePattern( final ICraftingPatternDetails craftingPatternDetails )
{
return this.patternDetailsIAEStackMultimap.containsKey( craftingPatternDetails );
}
public boolean containsMissingIAEStack( final IAEStack stack )
{
if( ( (IAEItemStack) stack ).getItem().isDamageable() )
{
for( IAEStack i : iaeStackPatternDetailsMultimap.keySet() )
{
if( i.fuzzyComparison( stack, FuzzyMode.IGNORE_ALL ) )
{
return true;
}
}
return false;
}
return this.iaeStackPatternDetailsMultimap.containsKey( stack );
}
public Collection<IAEStack> getMissingIAEStack( final ICraftingPatternDetails patternDetails )
{
return this.patternDetailsIAEStackMultimap.get( patternDetails );
}
public Collection<ICraftingPatternDetails> getIncompletablePattern( final IAEStack stack )
{
Collection<ICraftingPatternDetails> a = new ArrayList<>();
if( ( (IAEItemStack) stack ).getItem().isDamageable() )
{
for( IAEStack i : iaeStackPatternDetailsMultimap.keySet() )
{
if( i.fuzzyComparison( stack, FuzzyMode.IGNORE_ALL ) )
{
a.addAll( this.iaeStackPatternDetailsMultimap.get( i ) );
}
}
return a;
}
return this.iaeStackPatternDetailsMultimap.get( stack );
}
private class SavedTransactions
{
private final boolean put;
private final ICraftingPatternDetails patternDetails;
private final IAEStack stack;
public SavedTransactions( final boolean putOperation, final ICraftingPatternDetails myPatternDetails, final IAEStack stack )
{
this.put = putOperation;
this.patternDetails = myPatternDetails;
this.stack = stack;
}
}
}
@@ -19,10 +19,6 @@
package appeng.me.storage;
import appeng.me.GridAccessException;
import appeng.me.helpers.MachineSource;
import appeng.tile.storage.TileDrive;
import com.google.common.collect.ImmutableList;
import net.minecraft.item.ItemStack;
import appeng.api.config.Actionable;
@@ -40,7 +36,6 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
private final ItemStack is;
private final ICellHandler handler;
private final IChestOrDrive cord;
private IActionSource source;
public DriveWatcher( final ICellInventoryHandler<T> i, final ItemStack is, final ICellHandler han, final IChestOrDrive cod )
{
@@ -48,7 +43,6 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
this.is = is;
this.handler = han;
this.cord = cod;
this.source = new MachineSource( cod );
}
public int getStatus()
@@ -72,14 +66,6 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
this.cord.blinkCell( this.getSlot() );
this.oldStatus = newStatus;
}
try
{
( (TileDrive) this.cord ).getProxy().getStorage().postAlterationOfStoredItems( this.getChannel(), ImmutableList.of( input.copy().setStackSize( input.getStackSize() - ( a == null ? 0 : a.getStackSize() ) ) ), this.source );
}
catch( GridAccessException e )
{
e.printStackTrace();
}
}
return a;
@@ -99,15 +85,6 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
this.cord.blinkCell( this.getSlot() );
this.oldStatus = newStatus;
}
try
{
( (TileDrive) this.cord ).getProxy().getStorage().postAlterationOfStoredItems( this.getChannel(), ImmutableList.of( request.copy().setStackSize( -a.getStackSize() ) ), this.source );
}
catch( GridAccessException e )
{
e.printStackTrace();
}
}
return a;
@@ -72,7 +72,7 @@ public class MEMonitorPassThrough<T extends IAEStack<T>> extends MEPassThrough<T
final IItemList<T> after = this.getInternal() == null ? this.getWrappedChannel().createList() : this.getInternal()
.getAvailableItems( new ItemListIgnoreCrafting( this.getWrappedChannel().createList() ) );
if( this.monitor != null && this.listeners.size() > 0 )
if( this.monitor != null )
{
this.monitor.addListener( this, this.monitor );
}
@@ -124,6 +124,12 @@ public class MEMonitorPassThrough<T extends IAEStack<T>> extends MEPassThrough<T
return verificationToken == this.monitor;
}
@Override
public boolean hasListeners()
{
return this.listeners.size() > 0;
}
@Override
public void postChange( final IBaseMonitor<T> monitor, final Iterable<T> change, final IActionSource source )
{
@@ -41,7 +41,7 @@ public class MEPassThrough<T extends IAEStack<T>> implements IMEInventoryHandler
this.setInternal( i );
}
public IMEInventory<T> getInternal()
protected IMEInventory<T> getInternal()
{
return this.internal;
}
@@ -19,9 +19,6 @@
package appeng.parts.automation;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.me.cache.CraftingGridCache;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@@ -153,14 +150,18 @@ public class PartExportBus extends PartSharedItemBus implements ICraftingRequest
final IAEItemStack ais = this.getConfig().getAEStackInSlot( slotToExport );
if( ais == null || this.itemToSend <= 0 )
{
continue;
}
if( ais == null || this.itemToSend <= 0 ) continue;
if( this.craftOnly() )
{
this.didSomething = this.craftingTracker.handleCrafting( slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc ) || this.didSomething;
if ( this.craftOnly() ) {
if (this.failedCraftTriesSlot[x] <= 0) {
this.didSomething = this.craftingTracker.handleCrafting(slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(),
this.getProxy().getGrid(), cg, this.mySrc) || this.didSomething;
if (this.didSomething) this.failedCraftTriesSlot[x] = 0;
else this.failedCraftTriesSlot[x] += 2;
}
this.failedCraftTriesSlot[x] -= 1;
continue;
}
@@ -179,15 +180,20 @@ public class PartExportBus extends PartSharedItemBus implements ICraftingRequest
}
else
{
if( inv.getStorageList().findPrecise( ais ) != null )
{
this.pushItemIntoTarget( destination, energy, inv, ais );
}
this.pushItemIntoTarget( destination, energy, inv, ais );
}
if( this.itemToSend == before && this.isCraftingEnabled() )
{
this.didSomething = this.craftingTracker.handleCrafting( slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(), this.getProxy().getGrid(), cg, this.mySrc ) || this.didSomething;
if (this.failedCraftTriesSlot[x] <= 0) {
this.didSomething = this.craftingTracker.handleCrafting(slotToExport, this.itemToSend, ais, destination, this.getTile().getWorld(),
this.getProxy().getGrid(), cg, this.mySrc) || this.didSomething;
if (this.didSomething) this.failedCraftTriesSlot[x] = 0;
else this.failedCraftTriesSlot[x] += 2;
}
this.failedCraftTriesSlot[x] -= 1;
}
}
@@ -206,7 +206,7 @@ public class PartFormationPlane extends PartAbstractFormationPlane<IAEItemStack>
@Override
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
{
if( channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
if( this.getProxy().isActive() && channel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
{
final List<IMEInventoryHandler> handler = new ArrayList<>( 1 );
handler.add( this.myHandler );
@@ -283,12 +283,12 @@ public class PartImportBus extends PartSharedItemBus implements IInventoryDestin
final ItemStack simResult;
if( this.getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
{
simResult = myAdaptor.simulateSimilarRemove( toSend, itemStackToImport, fzMode, null );
simResult = myAdaptor.simulateSimilarRemove( toSend, itemStackToImport, fzMode, this );
itemAmountNotStorable = inv.injectItems( AEItemStack.fromItemStack( simResult ), Actionable.SIMULATE, this.source );
}
else
{
simResult = myAdaptor.simulateRemove( toSend, itemStackToImport, null );
simResult = myAdaptor.simulateRemove( toSend, itemStackToImport, this );
itemAmountNotStorable = inv.injectItems( AEItemStack.fromItemStack( simResult ), Actionable.SIMULATE, this.source );
}
@@ -19,44 +19,20 @@
package appeng.parts.automation;
import appeng.api.AEApi;
import appeng.api.config.*;
import appeng.api.networking.crafting.*;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.energy.IEnergyWatcher;
import appeng.api.networking.energy.IEnergyWatcherHost;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkCraftingPatternChange;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.networking.storage.IStackWatcher;
import appeng.api.networking.storage.IStackWatcherHost;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartModel;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.api.util.IConfigManager;
import appeng.core.AppEng;
import appeng.core.sync.GuiBridge;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import java.util.Collections;
import java.util.Optional;
import java.util.Random;
import appeng.api.networking.events.*;
import appeng.me.Grid;
import appeng.me.GridNode;
import appeng.me.cache.NetworkMonitor;
import appeng.parts.PartModel;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.util.Platform;
import appeng.util.inv.InvOperation;
import appeng.util.item.AEItemStack;
import appeng.util.item.OreHelper;
import appeng.util.item.OreReference;
import it.unimi.dsi.fastutil.objects.Object2LongMap;
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
@@ -70,8 +46,46 @@ import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import java.util.Optional;
import java.util.Random;
import appeng.api.AEApi;
import appeng.api.config.FuzzyMode;
import appeng.api.config.LevelType;
import appeng.api.config.RedstoneMode;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.config.YesNo;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.crafting.ICraftingProvider;
import appeng.api.networking.crafting.ICraftingProviderHelper;
import appeng.api.networking.crafting.ICraftingWatcher;
import appeng.api.networking.crafting.ICraftingWatcherHost;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.energy.IEnergyWatcher;
import appeng.api.networking.energy.IEnergyWatcherHost;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.networking.storage.IStackWatcher;
import appeng.api.networking.storage.IStackWatcherHost;
import appeng.api.parts.IPartCollisionHelper;
import appeng.api.parts.IPartModel;
import appeng.api.storage.IMEMonitor;
import appeng.api.storage.IMEMonitorHandlerReceiver;
import appeng.api.storage.IStorageChannel;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import appeng.api.util.IConfigManager;
import appeng.core.AppEng;
import appeng.core.sync.GuiBridge;
import appeng.helpers.Reflected;
import appeng.items.parts.PartModels;
import appeng.me.GridAccessException;
import appeng.parts.PartModel;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.util.Platform;
import appeng.util.inv.InvOperation;
public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherHost, IStackWatcherHost, ICraftingWatcherHost, IMEMonitorHandlerReceiver<IAEItemStack>, ICraftingProvider
@@ -363,7 +377,7 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
}
@Override
public void onStackChange( IItemList<?> o, IAEStack<?> fullStack, IAEStack<?> diffStack, IActionSource src, IStorageChannel<?> chan )
public void onStackChange( final IAEStack diffStack, final IStorageChannel chan )
{
if( chan == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
{
@@ -21,7 +21,6 @@ package appeng.parts.misc;
import javax.annotation.Nullable;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.config.Settings;
import appeng.api.config.StorageFilter;
@@ -34,7 +33,6 @@ import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.core.AELog;
import appeng.me.GridAccessException;
import appeng.me.helpers.IGridProxyable;
import appeng.me.storage.ITickingMonitor;
import appeng.util.inv.ItemHandlerIterator;
@@ -60,7 +58,6 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
private final IGridProxyable proxyable;
private final InventoryCache cache;
private StorageFilter mode;
private AccessRestriction access;
private ItemStack stackCache = null;
@@ -72,10 +69,8 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
{
PartStorageBus partStorageBus = (PartStorageBus) this.proxyable;
this.mode = ( (StorageFilter) partStorageBus.getConfigManager().getSetting( Settings.STORAGE_FILTER ) );
this.access = ( (AccessRestriction) partStorageBus.getConfigManager().getSetting( Settings.ACCESS ) );
}
this.cache = new InventoryCache( this.itemHandler, this.mode );
this.cache.update();
}
@Override
@@ -102,7 +97,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
ItemStack remaining = orgInput;
for( int i = 0; i < slotCount && !remaining.isEmpty(); i++ )
for ( int i = 0; i < slotCount && !remaining.isEmpty(); i++ )
{
remaining = this.itemHandler.insertItem( i, remaining, type == Actionable.SIMULATE );
}
@@ -122,17 +117,9 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
if( type == Actionable.MODULATE )
{
IAEItemStack added = iox.copy().setStackSize( iox.getStackSize() - remaining.getCount() );
this.cache.currentlyCached.add( added );
this.postDifference( Collections.singletonList( added ) );
try
{
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
}
catch( GridAccessException ex )
{
// meh
}
this.cache
.currentlyCached
.add( AEItemStack.fromItemStack( orgInput ).setStackSize( orgInput.getCount() - remaining.getCount() ) );
}
return AEItemStack.fromItemStack( remaining );
@@ -206,19 +193,10 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
IAEItemStack gatheredAEItemStack = AEItemStack.fromItemStack( gathered );
if( mode == Actionable.MODULATE )
{
IAEItemStack cachedStack = this.cache.currentlyCached.findPrecise( request );
if( cachedStack != null )
IAEItemStack e = this.cache.currentlyCached.findPrecise( gatheredAEItemStack );
if (e != null)
{
cachedStack.decStackSize( gatheredAEItemStack.getStackSize() );
this.postDifference( Collections.singletonList( gatheredAEItemStack.copy().setStackSize( -gatheredAEItemStack.getStackSize() ) ) );
}
try
{
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
}
catch( GridAccessException ex )
{
// meh
e.decStackSize( gathered.getCount() );
}
}
@@ -232,7 +210,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
public TickRateModulation onTick()
{
List<IAEItemStack> changes = this.cache.update();
if( !changes.isEmpty() && access.hasPermission( AccessRestriction.READ ) )
if( !changes.isEmpty() )
{
this.postDifference( changes );
return TickRateModulation.URGENT;
@@ -297,6 +275,7 @@ class ItemHandlerAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<IAE
private final StorageFilter mode;
IItemList<IAEItemStack> currentlyCached = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
public InventoryCache( IItemHandler itemHandler, StorageFilter mode )
{
this.mode = mode;
@@ -2,9 +2,7 @@ package appeng.parts.misc;
import javax.annotation.Nullable;
import appeng.api.AEApi;
import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable;
import appeng.api.config.Settings;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.networking.ticking.TickRateModulation;
@@ -15,7 +13,6 @@ import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.core.AELog;
import appeng.me.GridAccessException;
import appeng.me.helpers.IGridProxyable;
import appeng.me.storage.ITickingMonitor;
import appeng.util.item.AEItemStack;
@@ -40,7 +37,6 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
private final IItemRepository itemRepository;
private final IGridProxyable proxyable;
private final InventoryCache cache;
private AccessRestriction access;
private ItemStack stackCache;
@@ -49,12 +45,6 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
this.itemRepository = itemRepository;
this.proxyable = proxy;
this.cache = new InventoryCache( this.itemRepository );
if( this.proxyable instanceof PartStorageBus )
{
PartStorageBus partStorageBus = (PartStorageBus) this.proxyable;
this.access = ( (AccessRestriction) partStorageBus.getConfigManager().getSetting( Settings.ACCESS ) );
}
this.cache.update();
}
@Override
@@ -79,7 +69,7 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
ItemStack remaining = this.itemRepository.insertItem( orgInput, type == Actionable.SIMULATE );
// Store the stack in the cache for next time.
if( !remaining.isEmpty() && remaining != orgInput )
if (!remaining.isEmpty() && remaining != orgInput)
{
stackCache = remaining;
}
@@ -93,17 +83,9 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
if( type == Actionable.MODULATE )
{
IAEItemStack added = iox.copy().setStackSize( iox.getStackSize() - remaining.getCount() );
this.cache.currentlyCached.add( added );
this.postDifference( Collections.singletonList( added ) );
try
{
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
}
catch( GridAccessException ex )
{
// meh
}
this.cache
.currentlyCached
.add( AEItemStack.fromItemStack( orgInput ).setStackSize( orgInput.getCount() - remaining.getCount() ) );
}
return AEItemStack.fromItemStack( remaining );
@@ -123,8 +105,7 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
{
// Something broke. It should never return more than we requested...
// We're going to silently eat the remainder
AELog.warn( "Mod that provided item handler %s is broken. Returned %s items while only requesting %d.",
this.itemRepository.getClass().getName(), extracted.toString(), remainingSize );
AELog.warn( "Mod that provided item handler %s is broken. Returned %s items while only requesting %d.", this.itemRepository.getClass().getName(), extracted.toString(), remainingSize );
extracted.setCount( remainingSize );
}
@@ -133,19 +114,10 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
IAEItemStack extractedAEItemStack = AEItemStack.fromItemStack( extracted );
if( mode == Actionable.MODULATE )
{
IAEItemStack cachedStack = this.cache.currentlyCached.findPrecise( request );
if (cachedStack != null)
IAEItemStack e = this.cache.currentlyCached.findPrecise( extractedAEItemStack );
if (e != null)
{
cachedStack.decStackSize( extractedAEItemStack.getStackSize() );
this.postDifference( Collections.singletonList( extractedAEItemStack.copy().setStackSize( -extractedAEItemStack.getStackSize() ) ) );
}
try
{
this.proxyable.getProxy().getTick().alertDevice( this.proxyable.getProxy().getNode() );
}
catch( GridAccessException ex )
{
// meh
e.decStackSize( extracted.getCount() );
}
}
return extractedAEItemStack;
@@ -198,15 +170,17 @@ class ItemRepositoryAdapter implements IMEInventory<IAEItemStack>, IBaseMonitor<
@Override
public TickRateModulation onTick()
{
List<IAEItemStack> changes = this.cache.update();
if( !changes.isEmpty() && access.hasPermission( AccessRestriction.READ ) )
{
this.postDifference( changes );
return TickRateModulation.URGENT;
}
else
{
return TickRateModulation.SLOWER;
List<IAEItemStack> changes = this.cache.update();
if( !changes.isEmpty() )
{
this.postDifference( changes );
return TickRateModulation.URGENT;
}
else
{
return TickRateModulation.SLOWER;
}
}
}
@@ -22,7 +22,6 @@ package appeng.parts.misc;
import java.util.Collections;
import java.util.List;
import appeng.api.config.AccessRestriction;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
@@ -56,7 +55,6 @@ public abstract class PartSharedStorageBus extends PartUpgradeable implements IG
{
private boolean wasActive = false;
private int priority = 0;
protected boolean accessChanged;
public PartSharedStorageBus( ItemStack is )
{
@@ -148,10 +146,6 @@ public abstract class PartSharedStorageBus extends PartUpgradeable implements IG
@Override
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
{
if( settingName instanceof AccessRestriction )
{
this.accessChanged = true;
}
this.resetCache( true );
this.getHost().markForSave();
}
@@ -23,9 +23,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Objects;
import appeng.fluids.parts.FluidHandlerAdapter;
import appeng.me.storage.MEPassThrough;
import appeng.util.ConfigManager;
import com.jaquadro.minecraft.storagedrawers.api.capabilities.IItemRepository;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -124,7 +121,6 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
private int handlerHash = 0;
private boolean wasActive = false;
private byte resetCacheLogic = 0;
private boolean accessChanged;
@Reflected
public PartStorageBus( final ItemStack is )
@@ -176,10 +172,6 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
@Override
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
{
if( settingName instanceof AccessRestriction )
{
this.accessChanged = true;
}
this.resetCache( true );
this.getHost().markForSave();
}
@@ -266,14 +258,6 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
@Override
public void postChange( final IBaseMonitor<IAEItemStack> monitor, final Iterable<IAEItemStack> change, final IActionSource source )
{
if( this.mySrc.machine().map( machine -> machine == this ).orElse( false ) && monitor != null )
{
AccessRestriction currentAccess = (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getSetting( Settings.ACCESS );
if( !currentAccess.hasPermission( AccessRestriction.READ ) )
{
return;
}
}
try
{
if( this.getProxy().isActive() )
@@ -364,28 +348,11 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
final boolean fullReset = this.resetCacheLogic == 2;
this.resetCacheLogic = 0;
final MEInventoryHandler<IAEItemStack> in = this.getInternalHandler();
final IMEInventory<IAEItemStack> in = this.getInternalHandler();
IItemList<IAEItemStack> before = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
boolean denyRead = false;
if( in != null )
{
if( accessChanged )
{
AccessRestriction currentAccess = (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getSetting( Settings.ACCESS );
AccessRestriction oldAccess = (AccessRestriction) ( (ConfigManager) this.getConfigManager() ).getOldSetting( Settings.ACCESS );
if( oldAccess.hasPermission( AccessRestriction.READ ) && !currentAccess.hasPermission( AccessRestriction.READ ) )
{
denyRead = true;
}
in.setBaseAccess( oldAccess );
before = in.getAvailableItems( before );
in.setBaseAccess( currentAccess );
accessChanged = false;
}
else
{
before = in.getAvailableItems( before );
}
before = in.getAvailableItems( before );
}
this.cached = false;
@@ -394,19 +361,16 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
this.handlerHash = 0;
}
final MEInventoryHandler<IAEItemStack> out = this.getInternalHandler();
final IMEInventory<IAEItemStack> out = this.getInternalHandler();
if( in != out || denyRead )
if( in != out )
{
IItemList<IAEItemStack> after = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
if( out != null && !denyRead )
if( out != null )
{
after = out.getAvailableItems( after );
}
Platform.postListChanges( before, after, this, this.mySrc );
}
}
@@ -467,6 +431,16 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
return Objects.hash( target, target.getCapability( Capabilities.STORAGE_MONITORABLE_ACCESSOR, targetSide ) );
}
if (ITEM_REPOSITORY_CAPABILITY != null && target.hasCapability( ITEM_REPOSITORY_CAPABILITY, targetSide ))
{
final IItemRepository handlerRepo = target.getCapability( ITEM_REPOSITORY_CAPABILITY, targetSide );
if( handlerRepo != null )
{
return Objects.hash( target, handlerRepo, handlerRepo.getAllItems().size() );
}
}
final IItemHandler itemHandler = target.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, targetSide );
if( itemHandler != null )
@@ -24,10 +24,8 @@ import java.io.IOException;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.channels.IFluidStorageChannel;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IItemList;
import appeng.fluids.util.AEFluidStack;
import io.netty.buffer.ByteBuf;
@@ -462,7 +460,7 @@ public abstract class AbstractPartMonitor extends AbstractPartDisplay implements
}
@Override
public void onStackChange( IItemList<?> o, IAEStack<?> fullStack, IAEStack<?> diffStack, IActionSource src, IStorageChannel<?> chan )
public void onStackChange( final IAEStack diffStack, final IStorageChannel chan )
{
if( this.configuredItem != null )
{
@@ -554,10 +554,14 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
@Override
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
{
this.updateHandler();
if( this.cellHandler != null && this.cellHandler.getChannel() == channel )
if( this.getProxy().isActive() )
{
return Collections.singletonList( this.cellHandler );
this.updateHandler();
if( this.cellHandler != null && this.cellHandler.getChannel() == channel )
{
return Collections.singletonList( this.cellHandler );
}
}
return Collections.emptyList();
}
@@ -688,16 +692,21 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
@Override
public void postChange( final IBaseMonitor<T> monitor, final Iterable<T> change, final IActionSource source )
{
try
if( source == TileChest.this.mySrc || source.machine().map( machine -> machine == TileChest.this ).orElse( false ) )
{
if( TileChest.this.getProxy().isActive() )
try
{
TileChest.this.getProxy().getStorage().postAlterationOfStoredItems( this.chan, change, TileChest.this.mySrc );
if( TileChest.this.getProxy().isActive() )
{
TileChest.this.getProxy().getStorage().postAlterationOfStoredItems( this.chan, change, TileChest.this.mySrc );
}
}
catch( final GridAccessException e )
{
// :(
}
} catch ( final GridAccessException e )
{
// :(
}
TileChest.this.blinkCell( 0 );
}
@@ -334,8 +334,13 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
@Override
public List<IMEInventoryHandler> getCellArray( final IStorageChannel channel )
{
this.updateState();
return this.inventoryHandlers.get( channel );
if( this.getProxy().isActive() )
{
this.updateState();
return this.inventoryHandlers.get( channel );
}
return Collections.emptyList();
}
@Override
@@ -418,12 +418,10 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
if( possible > 0 )
{
IAEStack injectable = s.copy();
possible = Math.min( possible, itemsToMove );
injectable.setStackSize( possible );
s.setStackSize( possible );
final IAEStack extracted = src.extractItems( injectable, Actionable.MODULATE, this.mySrc );
final IAEStack extracted = src.extractItems( s, Actionable.MODULATE, this.mySrc );
if( extracted != null )
{
possible = extracted.getStackSize();
@@ -502,9 +500,8 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
final IAEStack test = myList.getFirstItem();
if( test != null )
{
IAEStack testCopy = test.copy();
testCopy.setStackSize( 1 );
return src.injectItems( testCopy, Actionable.SIMULATE, this.mySrc ) != null;
test.setStackSize( 1 );
return src.injectItems( test, Actionable.SIMULATE, this.mySrc ) != null;
}
return false;
}
@@ -36,7 +36,6 @@ public final class ConfigManager implements IConfigManager
{
private final Map<Settings, Enum<?>> settings = new EnumMap<>( Settings.class );
private final IConfigManagerHost target;
private Map<Settings, Enum<?>> oldSettings = new EnumMap<>( Settings.class );
public ConfigManager( final IConfigManagerHost tile )
{
@@ -73,15 +72,10 @@ public final class ConfigManager implements IConfigManager
{
final Enum<?> oldValue = this.getSetting( settingName );
this.settings.put( settingName, newValue );
this.oldSettings.put( settingName, oldValue );
this.target.updateSetting( this, settingName, newValue );
return oldValue;
}
public Enum<?> getOldSetting(final Settings settingName){
return this.oldSettings.get( settingName );
}
/**
* save all settings using config manager.
*