Crafting API Added
Fixed tons of issues with CPU multi block weirdness.
This commit is contained in:
@@ -12,10 +12,9 @@ import appeng.api.storage.ITerminalHost;
|
|||||||
import appeng.api.storage.data.IAEItemStack;
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
import appeng.container.AEBaseContainer;
|
import appeng.container.AEBaseContainer;
|
||||||
import appeng.container.slot.SlotInaccessable;
|
import appeng.container.slot.SlotInaccessable;
|
||||||
import appeng.crafting.ICraftingHost;
|
|
||||||
import appeng.tile.inventory.AppEngInternalInventory;
|
import appeng.tile.inventory.AppEngInternalInventory;
|
||||||
|
|
||||||
public class ContainerCraftAmount extends AEBaseContainer implements ICraftingHost
|
public class ContainerCraftAmount extends AEBaseContainer
|
||||||
{
|
{
|
||||||
|
|
||||||
ITerminalHost priHost;
|
ITerminalHost priHost;
|
||||||
@@ -38,7 +37,6 @@ public class ContainerCraftAmount extends AEBaseContainer implements ICraftingHo
|
|||||||
verifyPermissions( SecurityPermissions.CRAFT, false );
|
verifyPermissions( SecurityPermissions.CRAFT, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public IGrid getGrid()
|
public IGrid getGrid()
|
||||||
{
|
{
|
||||||
IActionHost h = ((IActionHost) this.getTarget());
|
IActionHost h = ((IActionHost) this.getTarget());
|
||||||
@@ -50,7 +48,6 @@ public class ContainerCraftAmount extends AEBaseContainer implements ICraftingHo
|
|||||||
return getPlayerInv().player.worldObj;
|
return getPlayerInv().player.worldObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public BaseActionSource getActionSrc()
|
public BaseActionSource getActionSrc()
|
||||||
{
|
{
|
||||||
return new PlayerSource( getPlayerInv().player, (IActionHost) getTarget() );
|
return new PlayerSource( getPlayerInv().player, (IActionHost) getTarget() );
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import appeng.api.AEApi;
|
|||||||
import appeng.api.config.Actionable;
|
import appeng.api.config.Actionable;
|
||||||
import appeng.api.config.SecurityPermissions;
|
import appeng.api.config.SecurityPermissions;
|
||||||
import appeng.api.networking.IGrid;
|
import appeng.api.networking.IGrid;
|
||||||
|
import appeng.api.networking.crafting.ICraftingGrid;
|
||||||
|
import appeng.api.networking.crafting.ICraftingJob;
|
||||||
import appeng.api.networking.security.BaseActionSource;
|
import appeng.api.networking.security.BaseActionSource;
|
||||||
import appeng.api.networking.security.IActionHost;
|
import appeng.api.networking.security.IActionHost;
|
||||||
import appeng.api.networking.security.PlayerSource;
|
import appeng.api.networking.security.PlayerSource;
|
||||||
@@ -26,16 +28,13 @@ import appeng.container.guisync.GuiSync;
|
|||||||
import appeng.core.AELog;
|
import appeng.core.AELog;
|
||||||
import appeng.core.sync.network.NetworkHandler;
|
import appeng.core.sync.network.NetworkHandler;
|
||||||
import appeng.core.sync.packets.PacketMEInventoryUpdate;
|
import appeng.core.sync.packets.PacketMEInventoryUpdate;
|
||||||
import appeng.crafting.CraftingJob;
|
|
||||||
import appeng.crafting.ICraftingHost;
|
|
||||||
import appeng.me.cache.CraftingCache;
|
|
||||||
|
|
||||||
public class ContainerCraftConfirm extends AEBaseContainer implements ICraftingHost
|
public class ContainerCraftConfirm extends AEBaseContainer
|
||||||
{
|
{
|
||||||
|
|
||||||
ITerminalHost priHost;
|
ITerminalHost priHost;
|
||||||
public Future<CraftingJob> job;
|
public Future<ICraftingJob> job;
|
||||||
public CraftingJob result;
|
public ICraftingJob result;
|
||||||
|
|
||||||
@GuiSync(0)
|
@GuiSync(0)
|
||||||
public long bytesUsed;
|
public long bytesUsed;
|
||||||
@@ -86,7 +85,7 @@ public class ContainerCraftConfirm extends AEBaseContainer implements ICraftingH
|
|||||||
PacketMEInventoryUpdate c = result.isSimulation() ? new PacketMEInventoryUpdate( (byte) 2 ) : null;
|
PacketMEInventoryUpdate c = result.isSimulation() ? new PacketMEInventoryUpdate( (byte) 2 ) : null;
|
||||||
|
|
||||||
IItemList<IAEItemStack> plan = AEApi.instance().storage().createItemList();
|
IItemList<IAEItemStack> plan = AEApi.instance().storage().createItemList();
|
||||||
result.tree.getPlan( plan );
|
result.populatePlan( plan );
|
||||||
|
|
||||||
bytesUsed = result.getByteTotal();
|
bytesUsed = result.getByteTotal();
|
||||||
|
|
||||||
@@ -162,7 +161,7 @@ public class ContainerCraftConfirm extends AEBaseContainer implements ICraftingH
|
|||||||
{
|
{
|
||||||
if ( result != null && simulation == false )
|
if ( result != null && simulation == false )
|
||||||
{
|
{
|
||||||
CraftingCache cc = getGrid().getCache( CraftingCache.class );
|
ICraftingGrid cc = getGrid().getCache( ICraftingGrid.class );
|
||||||
cc.submitJob( result, null, getActionSrc() );
|
cc.submitJob( result, null, getActionSrc() );
|
||||||
this.isContainerValid = false;
|
this.isContainerValid = false;
|
||||||
}
|
}
|
||||||
@@ -190,7 +189,6 @@ public class ContainerCraftConfirm extends AEBaseContainer implements ICraftingH
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public IGrid getGrid()
|
public IGrid getGrid()
|
||||||
{
|
{
|
||||||
IActionHost h = ((IActionHost) this.getTarget());
|
IActionHost h = ((IActionHost) this.getTarget());
|
||||||
@@ -202,7 +200,6 @@ public class ContainerCraftConfirm extends AEBaseContainer implements ICraftingH
|
|||||||
return getPlayerInv().player.worldObj;
|
return getPlayerInv().player.worldObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public BaseActionSource getActionSrc()
|
public BaseActionSource getActionSrc()
|
||||||
{
|
{
|
||||||
return new PlayerSource( getPlayerInv().player, (IActionHost) getTarget() );
|
return new PlayerSource( getPlayerInv().player, (IActionHost) getTarget() );
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import appeng.api.features.IRecipeHandlerRegistry;
|
|||||||
import appeng.api.features.IWirelessTermHandler;
|
import appeng.api.features.IWirelessTermHandler;
|
||||||
import appeng.api.movable.IMovableRegistry;
|
import appeng.api.movable.IMovableRegistry;
|
||||||
import appeng.api.networking.IGridCacheRegistry;
|
import appeng.api.networking.IGridCacheRegistry;
|
||||||
|
import appeng.api.networking.crafting.ICraftingGrid;
|
||||||
import appeng.api.networking.energy.IEnergyGrid;
|
import appeng.api.networking.energy.IEnergyGrid;
|
||||||
import appeng.api.networking.pathing.IPathingGrid;
|
import appeng.api.networking.pathing.IPathingGrid;
|
||||||
import appeng.api.networking.security.ISecurityGrid;
|
import appeng.api.networking.security.ISecurityGrid;
|
||||||
@@ -123,7 +124,7 @@ import appeng.items.tools.quartz.ToolQuartzPickaxe;
|
|||||||
import appeng.items.tools.quartz.ToolQuartzSpade;
|
import appeng.items.tools.quartz.ToolQuartzSpade;
|
||||||
import appeng.items.tools.quartz.ToolQuartzSword;
|
import appeng.items.tools.quartz.ToolQuartzSword;
|
||||||
import appeng.items.tools.quartz.ToolQuartzWrench;
|
import appeng.items.tools.quartz.ToolQuartzWrench;
|
||||||
import appeng.me.cache.CraftingCache;
|
import appeng.me.cache.CraftingGridCache;
|
||||||
import appeng.me.cache.EnergyGridCache;
|
import appeng.me.cache.EnergyGridCache;
|
||||||
import appeng.me.cache.GridStorageCache;
|
import appeng.me.cache.GridStorageCache;
|
||||||
import appeng.me.cache.P2PCache;
|
import appeng.me.cache.P2PCache;
|
||||||
@@ -523,7 +524,7 @@ public class Registration
|
|||||||
gcr.registerGridCache( P2PCache.class, P2PCache.class );
|
gcr.registerGridCache( P2PCache.class, P2PCache.class );
|
||||||
gcr.registerGridCache( ISpatialCache.class, SpatialPylonCache.class );
|
gcr.registerGridCache( ISpatialCache.class, SpatialPylonCache.class );
|
||||||
gcr.registerGridCache( ISecurityGrid.class, SecurityCache.class );
|
gcr.registerGridCache( ISecurityGrid.class, SecurityCache.class );
|
||||||
gcr.registerGridCache( CraftingCache.class, CraftingCache.class );
|
gcr.registerGridCache( ICraftingGrid.class, CraftingGridCache.class );
|
||||||
|
|
||||||
AEApi.instance().registries().externalStorage().addExternalStorageInterface( new AEExternalHandler() );
|
AEApi.instance().registries().externalStorage().addExternalStorageInterface( new AEExternalHandler() );
|
||||||
|
|
||||||
@@ -664,9 +665,9 @@ public class Registration
|
|||||||
|
|
||||||
private void registerSpatial(boolean force)
|
private void registerSpatial(boolean force)
|
||||||
{
|
{
|
||||||
if ( ! AEConfig.instance.isFeatureEnabled( AEFeature.SpatialIO ) )
|
if ( !AEConfig.instance.isFeatureEnabled( AEFeature.SpatialIO ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AEConfig config = AEConfig.instance;
|
AEConfig config = AEConfig.instance;
|
||||||
|
|
||||||
if ( storageBiome == null )
|
if ( storageBiome == null )
|
||||||
@@ -675,8 +676,8 @@ public class Registration
|
|||||||
{
|
{
|
||||||
config.storageBiomeID = Platform.findEmpty( BiomeGenBase.getBiomeGenArray() );
|
config.storageBiomeID = Platform.findEmpty( BiomeGenBase.getBiomeGenArray() );
|
||||||
if ( config.storageBiomeID == -1 )
|
if ( config.storageBiomeID == -1 )
|
||||||
throw new RuntimeException("Biome Array is full, please free up some Biome ID's or disable spatial.");
|
throw new RuntimeException( "Biome Array is full, please free up some Biome ID's or disable spatial." );
|
||||||
|
|
||||||
storageBiome = new BiomeGenStorage( config.storageBiomeID );
|
storageBiome = new BiomeGenStorage( config.storageBiomeID );
|
||||||
config.save();
|
config.save();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,19 +4,18 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.ThreadFactory;
|
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
import appeng.api.AEApi;
|
import appeng.api.AEApi;
|
||||||
import appeng.api.config.Actionable;
|
|
||||||
import appeng.api.networking.IGrid;
|
import appeng.api.networking.IGrid;
|
||||||
import appeng.api.networking.IGridHost;
|
import appeng.api.networking.IGridHost;
|
||||||
import appeng.api.networking.IGridNode;
|
import appeng.api.networking.IGridNode;
|
||||||
|
import appeng.api.networking.crafting.ICraftingGrid;
|
||||||
|
import appeng.api.networking.crafting.ICraftingJob;
|
||||||
import appeng.api.storage.data.IAEItemStack;
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
import appeng.container.ContainerOpenContext;
|
import appeng.container.ContainerOpenContext;
|
||||||
import appeng.container.implementations.ContainerCraftAmount;
|
import appeng.container.implementations.ContainerCraftAmount;
|
||||||
@@ -25,7 +24,6 @@ import appeng.core.AELog;
|
|||||||
import appeng.core.sync.AppEngPacket;
|
import appeng.core.sync.AppEngPacket;
|
||||||
import appeng.core.sync.GuiBridge;
|
import appeng.core.sync.GuiBridge;
|
||||||
import appeng.core.sync.network.INetworkInfo;
|
import appeng.core.sync.network.INetworkInfo;
|
||||||
import appeng.crafting.CraftingJob;
|
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
import appeng.util.item.AEItemStack;
|
import appeng.util.item.AEItemStack;
|
||||||
|
|
||||||
@@ -34,22 +32,6 @@ public class PacketCraftRequest extends AppEngPacket
|
|||||||
|
|
||||||
final public IAEItemStack slotItem;
|
final public IAEItemStack slotItem;
|
||||||
final public boolean heldShift;
|
final public boolean heldShift;
|
||||||
final public static ExecutorService craftingPool;
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
ThreadFactory factory = new ThreadFactory() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Thread newThread(Runnable ar)
|
|
||||||
{
|
|
||||||
return new Thread( ar, "AE Crafting Calculator" );
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
craftingPool = Executors.newCachedThreadPool( factory );
|
|
||||||
}
|
|
||||||
|
|
||||||
// automatic.
|
// automatic.
|
||||||
public PacketCraftRequest(ByteBuf stream) throws IOException {
|
public PacketCraftRequest(ByteBuf stream) throws IOException {
|
||||||
@@ -75,9 +57,12 @@ public class PacketCraftRequest extends AppEngPacket
|
|||||||
if ( g == null )
|
if ( g == null )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Future<ICraftingJob> futureJob = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CraftingJob cj = new CraftingJob( cca.getWorld(), cca, slotItem, Actionable.SIMULATE );
|
ICraftingGrid cg = g.getCache( ICraftingGrid.class );
|
||||||
|
futureJob = cg.beginCraftingJob( cca.getWorld(), cca.getGrid(), cca.getActionSrc(), slotItem, null );
|
||||||
|
|
||||||
ContainerOpenContext context = cca.openContext;
|
ContainerOpenContext context = cca.openContext;
|
||||||
if ( context != null )
|
if ( context != null )
|
||||||
@@ -89,7 +74,7 @@ public class PacketCraftRequest extends AppEngPacket
|
|||||||
{
|
{
|
||||||
ContainerCraftConfirm ccc = (ContainerCraftConfirm) player.openContainer;
|
ContainerCraftConfirm ccc = (ContainerCraftConfirm) player.openContainer;
|
||||||
ccc.autoStart = heldShift;
|
ccc.autoStart = heldShift;
|
||||||
ccc.job = craftingPool.submit( cj, cj );
|
ccc.job = futureJob;
|
||||||
cca.detectAndSendChanges();
|
cca.detectAndSendChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,6 +82,8 @@ public class PacketCraftRequest extends AppEngPacket
|
|||||||
}
|
}
|
||||||
catch (Throwable e)
|
catch (Throwable e)
|
||||||
{
|
{
|
||||||
|
if ( futureJob != null )
|
||||||
|
futureJob.cancel( true );
|
||||||
AELog.error( e );
|
AELog.error( e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-12
@@ -8,6 +8,10 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import appeng.api.AEApi;
|
import appeng.api.AEApi;
|
||||||
import appeng.api.config.Actionable;
|
import appeng.api.config.Actionable;
|
||||||
|
import appeng.api.networking.IGrid;
|
||||||
|
import appeng.api.networking.crafting.ICraftingCallback;
|
||||||
|
import appeng.api.networking.crafting.ICraftingGrid;
|
||||||
|
import appeng.api.networking.crafting.ICraftingJob;
|
||||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||||
import appeng.api.networking.security.BaseActionSource;
|
import appeng.api.networking.security.BaseActionSource;
|
||||||
import appeng.api.networking.storage.IStorageGrid;
|
import appeng.api.networking.storage.IStorageGrid;
|
||||||
@@ -15,12 +19,11 @@ import appeng.api.storage.data.IAEItemStack;
|
|||||||
import appeng.api.storage.data.IItemList;
|
import appeng.api.storage.data.IItemList;
|
||||||
import appeng.core.AELog;
|
import appeng.core.AELog;
|
||||||
import appeng.hooks.TickHandler;
|
import appeng.hooks.TickHandler;
|
||||||
import appeng.me.cache.CraftingCache;
|
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
|
|
||||||
import com.google.common.base.Stopwatch;
|
import com.google.common.base.Stopwatch;
|
||||||
|
|
||||||
public class CraftingJob implements Runnable
|
public class CraftingJob implements Runnable, ICraftingJob
|
||||||
{
|
{
|
||||||
|
|
||||||
IAEItemStack output;
|
IAEItemStack output;
|
||||||
@@ -29,14 +32,14 @@ public class CraftingJob implements Runnable
|
|||||||
|
|
||||||
HashSet<IAEItemStack> prophecies;
|
HashSet<IAEItemStack> prophecies;
|
||||||
|
|
||||||
ICraftingHost jobHost;
|
|
||||||
|
|
||||||
boolean simulate = false;
|
boolean simulate = false;
|
||||||
final MECraftingInventory original;
|
final MECraftingInventory original;
|
||||||
final MECraftingInventory availableCheck;
|
final MECraftingInventory availableCheck;
|
||||||
|
|
||||||
public CraftingTreeNode tree;
|
public CraftingTreeNode tree;
|
||||||
private BaseActionSource actionSrc;
|
private BaseActionSource actionSrc;
|
||||||
|
private ICraftingCallback callback;
|
||||||
|
|
||||||
long bytes = 0;
|
long bytes = 0;
|
||||||
World world;
|
World world;
|
||||||
|
|
||||||
@@ -45,8 +48,7 @@ public class CraftingJob implements Runnable
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CraftingJob(World w, ICraftingHost host, NBTTagCompound data) {
|
public CraftingJob(World w, NBTTagCompound data) {
|
||||||
jobHost = host;
|
|
||||||
world = wrapWorld( w );
|
world = wrapWorld( w );
|
||||||
storage = AEApi.instance().storage().createItemList();
|
storage = AEApi.instance().storage().createItemList();
|
||||||
prophecies = new HashSet();
|
prophecies = new HashSet();
|
||||||
@@ -59,16 +61,16 @@ public class CraftingJob implements Runnable
|
|||||||
return availableCheck.extractItems( available, Actionable.MODULATE, this.actionSrc );
|
return availableCheck.extractItems( available, Actionable.MODULATE, this.actionSrc );
|
||||||
}
|
}
|
||||||
|
|
||||||
public CraftingJob(World w, ICraftingHost host, IAEItemStack what, Actionable mode) {
|
public CraftingJob(World w, IGrid grid, BaseActionSource actionSrc, IAEItemStack what, ICraftingCallback callback) {
|
||||||
jobHost = host;
|
|
||||||
world = wrapWorld( w );
|
world = wrapWorld( w );
|
||||||
output = what.copy();
|
output = what.copy();
|
||||||
storage = AEApi.instance().storage().createItemList();
|
storage = AEApi.instance().storage().createItemList();
|
||||||
prophecies = new HashSet();
|
prophecies = new HashSet();
|
||||||
actionSrc = host.getActionSrc();
|
this.actionSrc = actionSrc;
|
||||||
|
|
||||||
CraftingCache cc = host.getGrid().getCache( CraftingCache.class );
|
this.callback = callback;
|
||||||
IStorageGrid sg = host.getGrid().getCache( IStorageGrid.class );
|
ICraftingGrid cc = grid.getCache( ICraftingGrid.class );
|
||||||
|
IStorageGrid sg = grid.getCache( IStorageGrid.class );
|
||||||
original = new MECraftingInventory( sg.getItemInventory(), false, false, false );
|
original = new MECraftingInventory( sg.getItemInventory(), false, false, false );
|
||||||
availableCheck = new MECraftingInventory( sg.getItemInventory(), false, false, false );
|
availableCheck = new MECraftingInventory( sg.getItemInventory(), false, false, false );
|
||||||
tree = getCraftingTree( cc, what );
|
tree = getCraftingTree( cc, what );
|
||||||
@@ -79,7 +81,7 @@ public class CraftingJob implements Runnable
|
|||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CraftingTreeNode getCraftingTree(CraftingCache cc, IAEItemStack what)
|
private CraftingTreeNode getCraftingTree(ICraftingGrid cc, IAEItemStack what)
|
||||||
{
|
{
|
||||||
return new CraftingTreeNode( cc, this, what, null, -1, 0 );
|
return new CraftingTreeNode( cc, this, what, null, -1, 0 );
|
||||||
}
|
}
|
||||||
@@ -225,6 +227,9 @@ public class CraftingJob implements Runnable
|
|||||||
|
|
||||||
public void finish()
|
public void finish()
|
||||||
{
|
{
|
||||||
|
if ( callback != null )
|
||||||
|
callback.calculationComplete( this );
|
||||||
|
|
||||||
synchronized (monitor)
|
synchronized (monitor)
|
||||||
{
|
{
|
||||||
running = false;
|
running = false;
|
||||||
@@ -339,4 +344,11 @@ public class CraftingJob implements Runnable
|
|||||||
bytes += crafts;
|
bytes += crafts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void populatePlan(IItemList<IAEItemStack> plan)
|
||||||
|
{
|
||||||
|
if ( tree != null )
|
||||||
|
tree.getPlan( plan );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import net.minecraft.world.World;
|
|||||||
import appeng.api.AEApi;
|
import appeng.api.AEApi;
|
||||||
import appeng.api.config.Actionable;
|
import appeng.api.config.Actionable;
|
||||||
import appeng.api.config.FuzzyMode;
|
import appeng.api.config.FuzzyMode;
|
||||||
|
import appeng.api.networking.crafting.ICraftingGrid;
|
||||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||||
import appeng.api.networking.security.BaseActionSource;
|
import appeng.api.networking.security.BaseActionSource;
|
||||||
import appeng.api.storage.data.IAEItemStack;
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
import appeng.api.storage.data.IItemList;
|
import appeng.api.storage.data.IItemList;
|
||||||
import appeng.me.cache.CraftingCache;
|
|
||||||
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
||||||
|
|
||||||
public class CraftingTreeNode
|
public class CraftingTreeNode
|
||||||
@@ -39,7 +39,7 @@ public class CraftingTreeNode
|
|||||||
|
|
||||||
boolean sim;
|
boolean sim;
|
||||||
|
|
||||||
public CraftingTreeNode(CraftingCache cc, CraftingJob job, IAEItemStack wat, CraftingTreeProcess par, int slot, int depth) {
|
public CraftingTreeNode(ICraftingGrid cc, CraftingJob job, IAEItemStack wat, CraftingTreeProcess par, int slot, int depth) {
|
||||||
what = wat;
|
what = wat;
|
||||||
parent = par;
|
parent = par;
|
||||||
this.slot = slot;
|
this.slot = slot;
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ import net.minecraft.world.World;
|
|||||||
import net.minecraft.world.WorldServer;
|
import net.minecraft.world.WorldServer;
|
||||||
import appeng.api.AEApi;
|
import appeng.api.AEApi;
|
||||||
import appeng.api.config.Actionable;
|
import appeng.api.config.Actionable;
|
||||||
|
import appeng.api.networking.crafting.ICraftingGrid;
|
||||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||||
import appeng.api.networking.security.BaseActionSource;
|
import appeng.api.networking.security.BaseActionSource;
|
||||||
import appeng.api.storage.data.IAEItemStack;
|
import appeng.api.storage.data.IAEItemStack;
|
||||||
import appeng.api.storage.data.IItemList;
|
import appeng.api.storage.data.IItemList;
|
||||||
import appeng.container.ContainerNull;
|
import appeng.container.ContainerNull;
|
||||||
import appeng.me.cache.CraftingCache;
|
|
||||||
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
import cpw.mods.fml.common.FMLCommonHandler;
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
@@ -38,7 +38,7 @@ public class CraftingTreeProcess
|
|||||||
Map<CraftingTreeNode, Long> nodes = new HashMap();
|
Map<CraftingTreeNode, Long> nodes = new HashMap();
|
||||||
public boolean possible = true;
|
public boolean possible = true;
|
||||||
|
|
||||||
public CraftingTreeProcess(CraftingCache cc, CraftingJob job, ICraftingPatternDetails details, CraftingTreeNode craftingTreeNode, int depth, World world) {
|
public CraftingTreeProcess(ICraftingGrid cc, CraftingJob job, ICraftingPatternDetails details, CraftingTreeNode craftingTreeNode, int depth, World world) {
|
||||||
parent = craftingTreeNode;
|
parent = craftingTreeNode;
|
||||||
this.details = details;
|
this.details = details;
|
||||||
this.job = job;
|
this.job = job;
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
package appeng.crafting;
|
|
||||||
|
|
||||||
import appeng.api.networking.IGrid;
|
|
||||||
import appeng.api.networking.security.BaseActionSource;
|
|
||||||
|
|
||||||
public interface ICraftingHost
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get Crafting cache for the host.
|
|
||||||
*/
|
|
||||||
IGrid getGrid();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get source of moving items around.
|
|
||||||
*
|
|
||||||
* @return {@link BaseActionSource} of host.
|
|
||||||
*/
|
|
||||||
BaseActionSource getActionSrc();
|
|
||||||
|
|
||||||
}
|
|
||||||
+60
-11
@@ -4,16 +4,25 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
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 net.minecraft.world.World;
|
||||||
import appeng.api.config.AccessRestriction;
|
import appeng.api.config.AccessRestriction;
|
||||||
import appeng.api.config.Actionable;
|
import appeng.api.config.Actionable;
|
||||||
import appeng.api.networking.IGrid;
|
import appeng.api.networking.IGrid;
|
||||||
import appeng.api.networking.IGridCache;
|
|
||||||
import appeng.api.networking.IGridHost;
|
import appeng.api.networking.IGridHost;
|
||||||
import appeng.api.networking.IGridNode;
|
import appeng.api.networking.IGridNode;
|
||||||
import appeng.api.networking.IGridStorage;
|
import appeng.api.networking.IGridStorage;
|
||||||
|
import appeng.api.networking.crafting.ICraftingCPU;
|
||||||
|
import appeng.api.networking.crafting.ICraftingCallback;
|
||||||
|
import appeng.api.networking.crafting.ICraftingGrid;
|
||||||
|
import appeng.api.networking.crafting.ICraftingJob;
|
||||||
import appeng.api.networking.crafting.ICraftingMedium;
|
import appeng.api.networking.crafting.ICraftingMedium;
|
||||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||||
import appeng.api.networking.crafting.ICraftingProvider;
|
import appeng.api.networking.crafting.ICraftingProvider;
|
||||||
@@ -36,10 +45,11 @@ import appeng.me.cluster.implementations.CraftingCPUCluster;
|
|||||||
import appeng.tile.crafting.TileCraftingStorageTile;
|
import appeng.tile.crafting.TileCraftingStorageTile;
|
||||||
import appeng.tile.crafting.TileCraftingTile;
|
import appeng.tile.crafting.TileCraftingTile;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableCollection;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
public class CraftingCache implements IGridCache, ICraftingProviderHelper, ICellProvider, IMEInventoryHandler
|
public class CraftingGridCache implements ICraftingGrid, ICraftingProviderHelper, ICellProvider, IMEInventoryHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
HashSet<CraftingCPUCluster> cpuClusters = new HashSet();
|
HashSet<CraftingCPUCluster> cpuClusters = new HashSet();
|
||||||
@@ -50,11 +60,11 @@ public class CraftingCache implements IGridCache, ICraftingProviderHelper, ICell
|
|||||||
IEnergyGrid eg;
|
IEnergyGrid eg;
|
||||||
|
|
||||||
HashMap<ICraftingPatternDetails, List<ICraftingMedium>> craftingMethods = new HashMap();
|
HashMap<ICraftingPatternDetails, List<ICraftingMedium>> craftingMethods = new HashMap();
|
||||||
HashMap<IAEItemStack, Set<ICraftingPatternDetails>> craftableItems = new HashMap();
|
HashMap<IAEItemStack, ImmutableSet<ICraftingPatternDetails>> craftableItems = new HashMap();
|
||||||
|
|
||||||
boolean updateList = false;
|
boolean updateList = false;
|
||||||
|
|
||||||
public CraftingCache(IGrid g) {
|
public CraftingGridCache(IGrid g) {
|
||||||
grid = g;
|
grid = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,22 +169,32 @@ public class CraftingCache implements IGridCache, ICraftingProviderHelper, ICell
|
|||||||
for (ICraftingProvider cp : providers)
|
for (ICraftingProvider cp : providers)
|
||||||
cp.provideCrafting( this );
|
cp.provideCrafting( this );
|
||||||
|
|
||||||
|
HashMap<IAEItemStack, Set<ICraftingPatternDetails>> tmpCraft = new HashMap();
|
||||||
|
|
||||||
// new craftables!
|
// new craftables!
|
||||||
for (ICraftingPatternDetails details : craftingMethods.keySet())
|
for (ICraftingPatternDetails details : craftingMethods.keySet())
|
||||||
|
{
|
||||||
for (IAEItemStack out : details.getOutputs())
|
for (IAEItemStack out : details.getOutputs())
|
||||||
{
|
{
|
||||||
out = out.copy();
|
out = out.copy();
|
||||||
out.reset();
|
out.reset();
|
||||||
out.setCraftable( true );
|
out.setCraftable( true );
|
||||||
|
|
||||||
Set<ICraftingPatternDetails> methods = craftableItems.get( out );
|
Set<ICraftingPatternDetails> methods = tmpCraft.get( out );
|
||||||
|
|
||||||
if ( methods == null )
|
if ( methods == null )
|
||||||
craftableItems.put( out, methods = new TreeSet() );
|
tmpCraft.put( out, methods = new TreeSet() );
|
||||||
|
|
||||||
methods.add( details );
|
methods.add( details );
|
||||||
sg.postAlterationOfStoredItems( StorageChannel.ITEMS, out, new BaseActionSource() );
|
sg.postAlterationOfStoredItems( StorageChannel.ITEMS, out, new BaseActionSource() );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// make them immutable
|
||||||
|
for (Entry<IAEItemStack, Set<ICraftingPatternDetails>> e : tmpCraft.entrySet())
|
||||||
|
{
|
||||||
|
craftableItems.put( e.getKey(), ImmutableSet.copyOf( e.getValue() ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -263,11 +283,16 @@ public class CraftingCache implements IGridCache, ICraftingProviderHelper, ICell
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean submitJob(CraftingJob job, CraftingCPUCluster target, BaseActionSource src)
|
public boolean submitJob(ICraftingJob job, ICraftingCPU target, BaseActionSource src)
|
||||||
{
|
{
|
||||||
if ( job.isSimulation() )
|
if ( job.isSimulation() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
CraftingCPUCluster cpuClust = null;
|
||||||
|
|
||||||
|
if ( target instanceof CraftingCPUCluster )
|
||||||
|
cpuClust = (CraftingCPUCluster) target;
|
||||||
|
|
||||||
if ( target == null )
|
if ( target == null )
|
||||||
{
|
{
|
||||||
// TODO real stuff...
|
// TODO real stuff...
|
||||||
@@ -275,13 +300,13 @@ public class CraftingCache implements IGridCache, ICraftingProviderHelper, ICell
|
|||||||
{
|
{
|
||||||
if ( !cpu.isBusy() )
|
if ( !cpu.isBusy() )
|
||||||
{
|
{
|
||||||
target = cpu;
|
cpuClust = cpu;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( target != null && target.submitJob( grid, job, src ) )
|
if ( cpuClust != null && cpuClust.submitJob( grid, job, src ) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -293,9 +318,9 @@ public class CraftingCache implements IGridCache, ICraftingProviderHelper, ICell
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<ICraftingPatternDetails> getCraftingFor(IAEItemStack what)
|
public ImmutableCollection<ICraftingPatternDetails> getCraftingFor(IAEItemStack what)
|
||||||
{
|
{
|
||||||
Set<ICraftingPatternDetails> res = craftableItems.get( what );
|
ImmutableSet<ICraftingPatternDetails> res = craftableItems.get( what );
|
||||||
if ( res == null )
|
if ( res == null )
|
||||||
return ImmutableSet.of();
|
return ImmutableSet.of();
|
||||||
return res;
|
return res;
|
||||||
@@ -317,4 +342,28 @@ public class CraftingCache implements IGridCache, ICraftingProviderHelper, ICell
|
|||||||
return i == 1;
|
return i == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final public static ExecutorService craftingPool;
|
||||||
|
|
||||||
|
static
|
||||||
|
{
|
||||||
|
ThreadFactory factory = new ThreadFactory() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Thread newThread(Runnable ar)
|
||||||
|
{
|
||||||
|
return new Thread( ar, "AE Crafting Calculator" );
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
craftingPool = Executors.newCachedThreadPool( factory );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Future<ICraftingJob> beginCraftingJob(World world, IGrid grid, BaseActionSource actionSrc, IAEItemStack slotItem, ICraftingCallback cb)
|
||||||
|
{
|
||||||
|
CraftingJob cj = new CraftingJob( world, grid, actionSrc, slotItem, cb );
|
||||||
|
return craftingPool.submit( cj, (ICraftingJob) cj );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -21,13 +21,14 @@ import appeng.api.networking.IGrid;
|
|||||||
import appeng.api.networking.IGridHost;
|
import appeng.api.networking.IGridHost;
|
||||||
import appeng.api.networking.IGridNode;
|
import appeng.api.networking.IGridNode;
|
||||||
import appeng.api.networking.crafting.CraftingItemList;
|
import appeng.api.networking.crafting.CraftingItemList;
|
||||||
|
import appeng.api.networking.crafting.ICraftingCPU;
|
||||||
|
import appeng.api.networking.crafting.ICraftingJob;
|
||||||
import appeng.api.networking.crafting.ICraftingMedium;
|
import appeng.api.networking.crafting.ICraftingMedium;
|
||||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||||
import appeng.api.networking.energy.IEnergyGrid;
|
import appeng.api.networking.energy.IEnergyGrid;
|
||||||
import appeng.api.networking.events.MENetworkCraftingCpuChange;
|
import appeng.api.networking.events.MENetworkCraftingCpuChange;
|
||||||
import appeng.api.networking.security.BaseActionSource;
|
import appeng.api.networking.security.BaseActionSource;
|
||||||
import appeng.api.networking.security.MachineSource;
|
import appeng.api.networking.security.MachineSource;
|
||||||
import appeng.api.networking.storage.IBaseMonitor;
|
|
||||||
import appeng.api.networking.storage.IStorageGrid;
|
import appeng.api.networking.storage.IStorageGrid;
|
||||||
import appeng.api.storage.IMEInventory;
|
import appeng.api.storage.IMEInventory;
|
||||||
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
||||||
@@ -40,14 +41,14 @@ import appeng.core.AELog;
|
|||||||
import appeng.crafting.CraftBranchFailure;
|
import appeng.crafting.CraftBranchFailure;
|
||||||
import appeng.crafting.CraftingJob;
|
import appeng.crafting.CraftingJob;
|
||||||
import appeng.crafting.MECraftingInventory;
|
import appeng.crafting.MECraftingInventory;
|
||||||
import appeng.me.cache.CraftingCache;
|
import appeng.me.cache.CraftingGridCache;
|
||||||
import appeng.me.cluster.IAECluster;
|
import appeng.me.cluster.IAECluster;
|
||||||
import appeng.tile.crafting.TileCraftingTile;
|
import appeng.tile.crafting.TileCraftingTile;
|
||||||
import appeng.util.Platform;
|
import appeng.util.Platform;
|
||||||
import appeng.util.item.AEItemStack;
|
import appeng.util.item.AEItemStack;
|
||||||
import cpw.mods.fml.common.FMLCommonHandler;
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
|
|
||||||
public class CraftingCPUCluster implements IAECluster, IBaseMonitor<IAEItemStack>
|
public class CraftingCPUCluster implements IAECluster, ICraftingCPU
|
||||||
{
|
{
|
||||||
|
|
||||||
class TaskProgress
|
class TaskProgress
|
||||||
@@ -73,6 +74,8 @@ public class CraftingCPUCluster implements IAECluster, IBaseMonitor<IAEItemStack
|
|||||||
private LinkedList<TileCraftingTile> storage = new LinkedList<TileCraftingTile>();
|
private LinkedList<TileCraftingTile> storage = new LinkedList<TileCraftingTile>();
|
||||||
private LinkedList<TileCraftingTile> status = new LinkedList<TileCraftingTile>();
|
private LinkedList<TileCraftingTile> status = new LinkedList<TileCraftingTile>();
|
||||||
|
|
||||||
|
long availableStorage = 0;
|
||||||
|
|
||||||
MachineSource machineSrc = null;
|
MachineSource machineSrc = null;
|
||||||
|
|
||||||
int accelerator = 0;
|
int accelerator = 0;
|
||||||
@@ -182,9 +185,7 @@ public class CraftingCPUCluster implements IAECluster, IBaseMonitor<IAEItemStack
|
|||||||
public void updateStatus(boolean updateGrid)
|
public void updateStatus(boolean updateGrid)
|
||||||
{
|
{
|
||||||
for (TileCraftingTile r : tiles)
|
for (TileCraftingTile r : tiles)
|
||||||
{
|
r.updateMeta( true );
|
||||||
r.updateMeta();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -213,6 +214,18 @@ public class CraftingCPUCluster implements IAECluster, IBaseMonitor<IAEItemStack
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getAvailableStorage()
|
||||||
|
{
|
||||||
|
return availableStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCoProcessors()
|
||||||
|
{
|
||||||
|
return accelerator;
|
||||||
|
}
|
||||||
|
|
||||||
public void addTile(TileCraftingTile te)
|
public void addTile(TileCraftingTile te)
|
||||||
{
|
{
|
||||||
if ( machineSrc == null || te.isCoreBlock )
|
if ( machineSrc == null || te.isCoreBlock )
|
||||||
@@ -223,7 +236,10 @@ public class CraftingCPUCluster implements IAECluster, IBaseMonitor<IAEItemStack
|
|||||||
tiles.add( te );
|
tiles.add( te );
|
||||||
|
|
||||||
if ( te.isStorage() )
|
if ( te.isStorage() )
|
||||||
|
{
|
||||||
|
availableStorage += te.getStorageBytes();
|
||||||
storage.add( te );
|
storage.add( te );
|
||||||
|
}
|
||||||
else if ( te.isStatus() )
|
else if ( te.isStatus() )
|
||||||
status.add( te );
|
status.add( te );
|
||||||
else if ( te.isAccelerator() )
|
else if ( te.isAccelerator() )
|
||||||
@@ -373,7 +389,7 @@ public class CraftingCPUCluster implements IAECluster, IBaseMonitor<IAEItemStack
|
|||||||
storeItems(); // marks dirty
|
storeItems(); // marks dirty
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateCraftingLogic(IGrid grid, IEnergyGrid eg, CraftingCache cc)
|
public void updateCraftingLogic(IGrid grid, IEnergyGrid eg, CraftingGridCache cc)
|
||||||
{
|
{
|
||||||
if ( isComplete )
|
if ( isComplete )
|
||||||
{
|
{
|
||||||
@@ -566,11 +582,14 @@ public class CraftingCPUCluster implements IAECluster, IBaseMonitor<IAEItemStack
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean submitJob(IGrid g, CraftingJob job, BaseActionSource src)
|
public boolean submitJob(IGrid g, ICraftingJob job, BaseActionSource src)
|
||||||
{
|
{
|
||||||
if ( !tasks.isEmpty() || !waitingFor.isEmpty() )
|
if ( !tasks.isEmpty() || !waitingFor.isEmpty() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if ( !(job instanceof CraftingJob) )
|
||||||
|
return false;
|
||||||
|
|
||||||
IStorageGrid sg = g.getCache( IStorageGrid.class );
|
IStorageGrid sg = g.getCache( IStorageGrid.class );
|
||||||
IMEInventory<IAEItemStack> storage = sg.getItemInventory();
|
IMEInventory<IAEItemStack> storage = sg.getItemInventory();
|
||||||
MECraftingInventory ci = new MECraftingInventory( storage, true, false, false );
|
MECraftingInventory ci = new MECraftingInventory( storage, true, false, false );
|
||||||
@@ -578,7 +597,7 @@ public class CraftingCPUCluster implements IAECluster, IBaseMonitor<IAEItemStack
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
waitingFor.resetStatus();
|
waitingFor.resetStatus();
|
||||||
job.tree.setJob( ci, this, src );
|
((CraftingJob) job).tree.setJob( ci, this, src );
|
||||||
ci.commit( src );
|
ci.commit( src );
|
||||||
finalOutput = job.getOutput();
|
finalOutput = job.getOutput();
|
||||||
waiting = false;
|
waiting = false;
|
||||||
@@ -621,6 +640,7 @@ public class CraftingCPUCluster implements IAECluster, IBaseMonitor<IAEItemStack
|
|||||||
i.value += crafts;
|
i.value += crafts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isBusy()
|
public boolean isBusy()
|
||||||
{
|
{
|
||||||
Iterator<Entry<ICraftingPatternDetails, TaskProgress>> i = tasks.entrySet().iterator();
|
Iterator<Entry<ICraftingPatternDetails, TaskProgress>> i = tasks.entrySet().iterator();
|
||||||
@@ -768,6 +788,7 @@ public class CraftingCPUCluster implements IAECluster, IBaseMonitor<IAEItemStack
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public BaseActionSource getActionSource()
|
public BaseActionSource getActionSource()
|
||||||
{
|
{
|
||||||
return machineSrc;
|
return machineSrc;
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP
|
|||||||
public void updateStatus(CraftingCPUCluster c)
|
public void updateStatus(CraftingCPUCluster c)
|
||||||
{
|
{
|
||||||
clust = c;
|
clust = c;
|
||||||
updateMeta();
|
updateMeta( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateMultiBlock()
|
public void updateMultiBlock()
|
||||||
@@ -116,51 +116,45 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP
|
|||||||
{
|
{
|
||||||
clust.destroy();
|
clust.destroy();
|
||||||
if ( update )
|
if ( update )
|
||||||
updateMeta();
|
updateMeta( true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MENetworkEventSubscribe
|
||||||
|
public void onPowerStateChage(MENetworkChannelsChanged ev)
|
||||||
|
{
|
||||||
|
updateMeta( false );
|
||||||
|
}
|
||||||
|
|
||||||
@MENetworkEventSubscribe
|
@MENetworkEventSubscribe
|
||||||
public void onPowerStateChage(MENetworkPowerStatusChange ev)
|
public void onPowerStateChage(MENetworkPowerStatusChange ev)
|
||||||
{
|
{
|
||||||
updateMeta();
|
updateMeta( false );
|
||||||
}
|
}
|
||||||
|
|
||||||
@MENetworkEventSubscribe
|
public void updateMeta(boolean updateFormed)
|
||||||
public void ChannelChangesd(MENetworkChannelsChanged ev)
|
|
||||||
{
|
{
|
||||||
updateMeta();
|
boolean formed = isFormed();
|
||||||
}
|
|
||||||
|
|
||||||
public void updateMeta()
|
|
||||||
{
|
|
||||||
if ( !gridProxy.isReady() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
boolean formed = clust != null;
|
|
||||||
boolean power = false;
|
boolean power = false;
|
||||||
power = gridProxy.isActive();
|
|
||||||
|
if ( gridProxy.isReady() )
|
||||||
|
power = gridProxy.isActive();
|
||||||
|
|
||||||
int current = worldObj.getBlockMetadata( xCoord, yCoord, zCoord );
|
int current = worldObj.getBlockMetadata( xCoord, yCoord, zCoord );
|
||||||
int newmeta = (current & 3) | (formed ? 8 : 0) | (power ? 4 : 0);
|
int newmeta = (current & 3) | (formed ? 8 : 0) | (power ? 4 : 0);
|
||||||
|
|
||||||
if ( current != newmeta )
|
if ( current != newmeta )
|
||||||
{
|
|
||||||
worldObj.setBlockMetadataWithNotify( xCoord, yCoord, zCoord, newmeta, 2 );
|
worldObj.setBlockMetadataWithNotify( xCoord, yCoord, zCoord, newmeta, 2 );
|
||||||
|
|
||||||
if ( isFormed() )
|
if ( updateFormed )
|
||||||
|
{
|
||||||
|
if ( formed )
|
||||||
gridProxy.setValidSides( EnumSet.allOf( ForgeDirection.class ) );
|
gridProxy.setValidSides( EnumSet.allOf( ForgeDirection.class ) );
|
||||||
else
|
else
|
||||||
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dropAndBreak()
|
|
||||||
{
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IAECluster getCluster()
|
public IAECluster getCluster()
|
||||||
{
|
{
|
||||||
@@ -176,12 +170,16 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP
|
|||||||
@Override
|
@Override
|
||||||
public boolean isPowered()
|
public boolean isPowered()
|
||||||
{
|
{
|
||||||
return (worldObj.getBlockMetadata( xCoord, yCoord, zCoord ) & 4) == 4;
|
if ( Platform.isClient() )
|
||||||
|
return (worldObj.getBlockMetadata( xCoord, yCoord, zCoord ) & 4) == 4;
|
||||||
|
return gridProxy.isActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFormed()
|
public boolean isFormed()
|
||||||
{
|
{
|
||||||
return (worldObj.getBlockMetadata( xCoord, yCoord, zCoord ) & 8) == 8;
|
if ( Platform.isClient() )
|
||||||
|
return (worldObj.getBlockMetadata( xCoord, yCoord, zCoord ) & 8) == 8;
|
||||||
|
return clust != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAccelerator()
|
public boolean isAccelerator()
|
||||||
|
|||||||
Reference in New Issue
Block a user