2013-12-27 23:59:59 +01:00
|
|
|
package appeng.parts.automation;
|
|
|
|
|
|
|
|
import net.minecraft.client.renderer.RenderBlocks;
|
2013-12-30 06:55:02 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-07-04 08:19:35 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2013-12-30 06:55:02 +01:00
|
|
|
import net.minecraft.util.Vec3;
|
2014-01-01 09:54:53 +01:00
|
|
|
import appeng.api.config.Actionable;
|
2013-12-30 06:55:02 +01:00
|
|
|
import appeng.api.config.FuzzyMode;
|
2014-07-04 08:19:35 +02:00
|
|
|
import appeng.api.config.PowerMultiplier;
|
2013-12-30 06:55:02 +01:00
|
|
|
import appeng.api.config.RedstoneMode;
|
|
|
|
import appeng.api.config.Settings;
|
2014-01-02 06:51:41 +01:00
|
|
|
import appeng.api.config.Upgrades;
|
2014-07-05 04:04:30 +02:00
|
|
|
import appeng.api.config.YesNo;
|
2013-12-30 06:55:02 +01:00
|
|
|
import appeng.api.networking.IGridNode;
|
2014-07-04 08:19:35 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingGrid;
|
|
|
|
import appeng.api.networking.crafting.ICraftingLink;
|
|
|
|
import appeng.api.networking.crafting.ICraftingRequester;
|
2014-01-01 09:54:53 +01:00
|
|
|
import appeng.api.networking.energy.IEnergyGrid;
|
2014-01-05 09:43:49 +01:00
|
|
|
import appeng.api.networking.security.BaseActionSource;
|
|
|
|
import appeng.api.networking.security.MachineSource;
|
2013-12-30 06:55:02 +01:00
|
|
|
import appeng.api.networking.ticking.IGridTickable;
|
|
|
|
import appeng.api.networking.ticking.TickRateModulation;
|
2014-03-17 20:59:50 +01:00
|
|
|
import appeng.api.networking.ticking.TickingRequest;
|
2014-09-20 22:20:53 +02:00
|
|
|
import appeng.api.parts.IPartCollisionHelper;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.parts.IPartRenderHelper;
|
2014-01-01 09:54:53 +01:00
|
|
|
import appeng.api.storage.IMEInventory;
|
2014-01-06 07:56:16 +01:00
|
|
|
import appeng.api.storage.IMEMonitor;
|
2014-01-01 09:54:53 +01:00
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.client.texture.CableBusTextures;
|
2014-07-04 08:19:35 +02:00
|
|
|
import appeng.core.AELog;
|
2014-03-17 20:59:50 +01:00
|
|
|
import appeng.core.settings.TickRates;
|
2013-12-30 06:55:02 +01:00
|
|
|
import appeng.core.sync.GuiBridge;
|
2014-07-05 18:53:16 +02:00
|
|
|
import appeng.helpers.MultiCraftingTracker;
|
2014-01-01 09:54:53 +01:00
|
|
|
import appeng.me.GridAccessException;
|
|
|
|
import appeng.util.InventoryAdaptor;
|
2013-12-30 06:55:02 +01:00
|
|
|
import appeng.util.Platform;
|
2014-07-04 08:19:35 +02:00
|
|
|
import appeng.util.item.AEItemStack;
|
2014-06-11 07:22:55 +02:00
|
|
|
|
|
|
|
import com.google.common.collect.ImmutableList;
|
2014-07-04 08:19:35 +02:00
|
|
|
import com.google.common.collect.ImmutableSet;
|
2014-06-11 07:22:55 +02:00
|
|
|
|
2014-02-07 06:51:19 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-07-04 08:19:35 +02:00
|
|
|
public class PartExportBus extends PartSharedItemBus implements IGridTickable, ICraftingRequester
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
2014-07-06 08:48:21 +02:00
|
|
|
final MultiCraftingTracker cratingTracker = new MultiCraftingTracker( this, 9 );
|
|
|
|
final BaseActionSource mySrc;
|
2014-01-05 09:43:49 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public PartExportBus(ItemStack is) {
|
|
|
|
super( PartExportBus.class, is );
|
2014-01-05 09:43:49 +01:00
|
|
|
settings.registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
2013-12-30 06:55:02 +01:00
|
|
|
settings.registerSetting( Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL );
|
2014-07-05 04:04:30 +02:00
|
|
|
settings.registerSetting( Settings.CRAFT_ONLY, YesNo.NO );
|
2014-01-05 09:43:49 +01:00
|
|
|
mySrc = new MachineSource( this );
|
2013-12-30 06:55:02 +01:00
|
|
|
}
|
|
|
|
|
2014-07-04 08:19:35 +02:00
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound extra)
|
|
|
|
{
|
|
|
|
super.readFromNBT( extra );
|
2014-07-05 18:53:16 +02:00
|
|
|
cratingTracker.readFromNBT( extra );
|
2014-07-04 08:19:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound extra)
|
|
|
|
{
|
|
|
|
super.writeToNBT( extra );
|
2014-07-05 18:53:16 +02:00
|
|
|
cratingTracker.writeToNBT( extra );
|
2014-07-04 08:19:35 +02:00
|
|
|
}
|
|
|
|
|
2013-12-30 06:55:02 +01:00
|
|
|
@Override
|
2014-02-20 06:18:49 +01:00
|
|
|
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
|
2013-12-30 06:55:02 +01:00
|
|
|
{
|
|
|
|
if ( !player.isSneaking() )
|
|
|
|
{
|
|
|
|
if ( Platform.isClient() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Platform.openGUI( player, getHost().getTile(), side, GuiBridge.GUI_BUS );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-07 06:51:19 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-12-27 23:59:59 +01:00
|
|
|
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
|
|
|
{
|
|
|
|
|
2014-04-04 06:31:10 +02:00
|
|
|
rh.setTexture( CableBusTextures.PartExportSides.getIcon(), CableBusTextures.PartExportSides.getIcon(), CableBusTextures.PartMonitorBack.getIcon(),
|
|
|
|
is.getIconIndex(), CableBusTextures.PartExportSides.getIcon(), CableBusTextures.PartExportSides.getIcon() );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
rh.setBounds( 4, 4, 12, 12, 12, 14 );
|
|
|
|
rh.renderInventoryBox( renderer );
|
|
|
|
|
|
|
|
rh.setBounds( 5, 5, 14, 11, 11, 15 );
|
|
|
|
rh.renderInventoryBox( renderer );
|
|
|
|
|
|
|
|
rh.setBounds( 6, 6, 15, 10, 10, 16 );
|
|
|
|
rh.renderInventoryBox( renderer );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-07 06:51:19 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-12-27 23:59:59 +01:00
|
|
|
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
|
|
|
{
|
2014-02-15 07:30:06 +01:00
|
|
|
renderCache = rh.useSimpliedRendering( x, y, z, this, renderCache );
|
2014-04-04 06:31:10 +02:00
|
|
|
rh.setTexture( CableBusTextures.PartExportSides.getIcon(), CableBusTextures.PartExportSides.getIcon(), CableBusTextures.PartMonitorBack.getIcon(),
|
|
|
|
is.getIconIndex(), CableBusTextures.PartExportSides.getIcon(), CableBusTextures.PartExportSides.getIcon() );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
rh.setBounds( 4, 4, 12, 12, 12, 14 );
|
|
|
|
rh.renderBlock( x, y, z, renderer );
|
|
|
|
|
|
|
|
rh.setBounds( 5, 5, 14, 11, 11, 15 );
|
|
|
|
rh.renderBlock( x, y, z, renderer );
|
|
|
|
|
|
|
|
rh.setBounds( 6, 6, 15, 10, 10, 16 );
|
|
|
|
rh.renderBlock( x, y, z, renderer );
|
|
|
|
|
|
|
|
rh.setTexture( CableBusTextures.PartMonitorSidesStatus.getIcon(), CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
|
|
|
CableBusTextures.PartMonitorBack.getIcon(), is.getIconIndex(), CableBusTextures.PartMonitorSidesStatus.getIcon(),
|
|
|
|
CableBusTextures.PartMonitorSidesStatus.getIcon() );
|
|
|
|
|
|
|
|
rh.setBounds( 6, 6, 11, 10, 10, 12 );
|
|
|
|
rh.renderBlock( x, y, z, renderer );
|
|
|
|
|
|
|
|
renderLights( x, y, z, rh, renderer );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int cableConnectionRenderTo()
|
|
|
|
{
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-09-20 22:20:53 +02:00
|
|
|
public void getBoxes(IPartCollisionHelper bch)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
bch.addBox( 4, 4, 12, 12, 12, 14 );
|
|
|
|
bch.addBox( 5, 5, 14, 11, 11, 15 );
|
|
|
|
bch.addBox( 6, 6, 15, 10, 10, 16 );
|
|
|
|
bch.addBox( 6, 6, 11, 10, 10, 12 );
|
|
|
|
}
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
long itemToSend = 1;
|
2014-01-06 07:56:16 +01:00
|
|
|
boolean didSomething = false;
|
|
|
|
|
2013-12-30 06:55:02 +01:00
|
|
|
@Override
|
2014-01-02 06:51:41 +01:00
|
|
|
TickRateModulation doBusWork()
|
2013-12-30 06:55:02 +01:00
|
|
|
{
|
2014-02-03 03:30:52 +01:00
|
|
|
if ( !proxy.isActive() )
|
|
|
|
return TickRateModulation.IDLE;
|
|
|
|
|
2014-01-06 07:56:16 +01:00
|
|
|
itemToSend = 1;
|
|
|
|
didSomething = false;
|
2014-01-02 06:51:41 +01:00
|
|
|
|
|
|
|
switch (getInstalledUpgrades( Upgrades.SPEED ))
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
itemToSend = 1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
itemToSend = 8;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
itemToSend = 32;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
itemToSend = 64;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
itemToSend = 96;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-01-01 09:54:53 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
InventoryAdaptor d = getHandler();
|
2014-01-06 07:56:16 +01:00
|
|
|
IMEMonitor<IAEItemStack> inv = proxy.getStorage().getItemInventory();
|
2014-01-01 09:54:53 +01:00
|
|
|
IEnergyGrid energy = proxy.getEnergy();
|
2014-07-05 18:53:16 +02:00
|
|
|
ICraftingGrid cg = proxy.getCrafting();
|
2014-01-06 07:56:16 +01:00
|
|
|
FuzzyMode fzMode = (FuzzyMode) getConfigManager().getSetting( Settings.FUZZY_MODE );
|
2014-01-01 09:54:53 +01:00
|
|
|
|
|
|
|
if ( d != null )
|
|
|
|
{
|
2014-01-06 07:56:16 +01:00
|
|
|
for (int x = 0; x < availableSlots() && itemToSend > 0; x++)
|
2014-01-01 09:54:53 +01:00
|
|
|
{
|
|
|
|
IAEItemStack ais = config.getAEStackInSlot( x );
|
2014-07-04 08:19:35 +02:00
|
|
|
if ( ais == null || itemToSend <= 0 || craftOnly() )
|
|
|
|
{
|
2014-07-05 18:53:16 +02:00
|
|
|
if ( isCraftingEnabled() )
|
|
|
|
didSomething = cratingTracker.handleCrafting( x, itemToSend, ais, d, getTile().getWorldObj(), proxy.getGrid(), cg, mySrc )
|
|
|
|
|| didSomething;
|
2014-01-06 07:56:16 +01:00
|
|
|
continue;
|
2014-07-04 08:19:35 +02:00
|
|
|
}
|
2014-01-01 09:54:53 +01:00
|
|
|
|
2014-07-05 04:04:30 +02:00
|
|
|
long before = itemToSend;
|
|
|
|
|
2014-01-06 07:56:16 +01:00
|
|
|
if ( getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
|
|
|
|
{
|
2014-06-11 07:22:55 +02:00
|
|
|
for (IAEItemStack o : ImmutableList.copyOf( inv.getStorageList().findFuzzy( ais, fzMode ) ))
|
2014-01-01 09:54:53 +01:00
|
|
|
{
|
2014-07-04 08:19:35 +02:00
|
|
|
pushItemIntoTarget( d, energy, inv, o );
|
2014-01-06 07:56:16 +01:00
|
|
|
if ( itemToSend <= 0 )
|
|
|
|
break;
|
2014-01-01 09:54:53 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-06 07:56:16 +01:00
|
|
|
else
|
2014-07-04 08:19:35 +02:00
|
|
|
pushItemIntoTarget( d, energy, inv, ais );
|
2014-07-05 04:04:30 +02:00
|
|
|
|
2014-07-05 18:53:16 +02:00
|
|
|
if ( itemToSend == before && isCraftingEnabled() )
|
|
|
|
didSomething = cratingTracker.handleCrafting( x, itemToSend, ais, d, getTile().getWorldObj(), proxy.getGrid(), cg, mySrc )
|
|
|
|
|| didSomething;
|
2014-01-01 09:54:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
|
|
|
return didSomething ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
2013-12-30 06:55:02 +01:00
|
|
|
}
|
|
|
|
|
2014-07-04 08:19:35 +02:00
|
|
|
private boolean craftOnly()
|
|
|
|
{
|
2014-07-05 04:04:30 +02:00
|
|
|
return getConfigManager().getSetting( Settings.CRAFT_ONLY ) == YesNo.YES;
|
2014-07-04 08:19:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isCraftingEnabled()
|
|
|
|
{
|
|
|
|
return getInstalledUpgrades( Upgrades.CRAFTING ) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void pushItemIntoTarget(InventoryAdaptor d, IEnergyGrid energy, IMEInventory<IAEItemStack> inv, IAEItemStack ais)
|
2014-01-06 07:56:16 +01:00
|
|
|
{
|
|
|
|
ItemStack is = ais.getItemStack();
|
2014-01-20 17:41:37 +01:00
|
|
|
is.stackSize = (int) itemToSend;
|
2014-01-06 07:56:16 +01:00
|
|
|
|
|
|
|
ItemStack o = d.simulateAdd( is );
|
2014-01-20 17:41:37 +01:00
|
|
|
long canFit = o == null ? itemToSend : itemToSend - o.stackSize;
|
2014-01-06 07:56:16 +01:00
|
|
|
|
|
|
|
if ( canFit > 0 )
|
|
|
|
{
|
|
|
|
ais = ais.copy();
|
|
|
|
ais.setStackSize( canFit );
|
|
|
|
IAEItemStack itemsToAdd = Platform.poweredExtraction( energy, inv, ais, mySrc );
|
|
|
|
|
|
|
|
if ( itemsToAdd != null )
|
|
|
|
{
|
|
|
|
itemToSend -= itemsToAdd.getStackSize();
|
|
|
|
|
|
|
|
ItemStack failed = d.addItems( itemsToAdd.getItemStack() );
|
|
|
|
if ( failed != null )
|
|
|
|
{
|
|
|
|
ais.setStackSize( failed.stackSize );
|
2014-01-20 17:41:37 +01:00
|
|
|
inv.injectItems( ais, Actionable.MODULATE, mySrc );
|
2014-01-06 07:56:16 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
didSomething = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-05 18:53:16 +02:00
|
|
|
@Override
|
|
|
|
public IAEItemStack injectCratedItems(ICraftingLink link, IAEItemStack items, Actionable mode)
|
|
|
|
{
|
|
|
|
InventoryAdaptor d = getHandler();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2014-07-05 23:52:15 +02:00
|
|
|
if ( d != null && proxy.isActive() )
|
2014-07-05 18:53:16 +02:00
|
|
|
{
|
|
|
|
IEnergyGrid energy = proxy.getEnergy();
|
|
|
|
|
|
|
|
double power = items.getStackSize();
|
|
|
|
if ( energy.extractAEPower( power, mode, PowerMultiplier.CONFIG ) > power - 0.01 )
|
|
|
|
{
|
|
|
|
if ( mode == Actionable.MODULATE )
|
|
|
|
return AEItemStack.create( d.addItems( items.getItemStack() ) );
|
|
|
|
return AEItemStack.create( d.simulateAdd( items.getItemStack() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
AELog.error( e );
|
|
|
|
}
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
2014-01-02 06:51:41 +01:00
|
|
|
@Override
|
|
|
|
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
|
|
|
{
|
|
|
|
return doBusWork();
|
|
|
|
}
|
|
|
|
|
|
|
|
public RedstoneMode getRSMode()
|
|
|
|
{
|
2014-01-05 09:43:49 +01:00
|
|
|
return (RedstoneMode) settings.getSetting( Settings.REDSTONE_CONTROLLED );
|
2014-01-02 06:51:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean isSleeping()
|
|
|
|
{
|
|
|
|
return getHandler() == null || super.isSleeping();
|
|
|
|
}
|
2014-03-17 20:59:50 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public TickingRequest getTickingRequest(IGridNode node)
|
|
|
|
{
|
2014-04-04 06:31:10 +02:00
|
|
|
return new TickingRequest( TickRates.ExportBus.min, TickRates.ExportBus.max, isSleeping(), false );
|
2014-03-17 20:59:50 +01:00
|
|
|
}
|
2014-07-04 08:19:35 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ImmutableSet<ICraftingLink> getRequestedJobs()
|
|
|
|
{
|
2014-07-05 18:53:16 +02:00
|
|
|
return cratingTracker.getRequestedJobs();
|
2014-07-04 08:19:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void jobStateChange(ICraftingLink link)
|
|
|
|
{
|
2014-07-05 18:53:16 +02:00
|
|
|
cratingTracker.jobStateChange( link );
|
2014-07-04 08:19:35 +02:00
|
|
|
}
|
2014-07-05 18:53:16 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|