This commit is contained in:
AlgorithmX2
2014-06-11 00:44:00 -05:00
19 changed files with 605 additions and 274 deletions
+117
View File
@@ -6,6 +6,8 @@ import java.util.Random;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.particle.EntityDiggingFX;
import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@@ -20,6 +22,8 @@ import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.parts.IPart;
import appeng.api.parts.IPartHost;
import appeng.api.parts.PartItemStack; import appeng.api.parts.PartItemStack;
import appeng.api.parts.SelectedPart; import appeng.api.parts.SelectedPart;
import appeng.block.AEBaseBlock; import appeng.block.AEBaseBlock;
@@ -39,6 +43,8 @@ import appeng.tile.AEBaseTile;
import appeng.tile.networking.TileCableBus; import appeng.tile.networking.TileCableBus;
import appeng.tile.networking.TileCableBusTESR; import appeng.tile.networking.TileCableBusTESR;
import appeng.util.Platform; import appeng.util.Platform;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockCableBus extends AEBaseBlock public class BlockCableBus extends AEBaseBlock
{ {
@@ -75,6 +81,117 @@ public class BlockCableBus extends AEBaseBlock
return 0; return 0;
} }
@SideOnly(Side.CLIENT)
public boolean addHitEffects(World world, MovingObjectPosition target, EffectRenderer effectRenderer)
{
Object pobj = cb( world, target.blockX, target.blockY, target.blockZ );
if ( pobj instanceof IPartHost )
{
IPartHost host = (IPartHost) pobj;
for (ForgeDirection side : ForgeDirection.values())
{
IPart p = host.getPart( side );
IIcon ico = getIcon( p );
if ( ico == null )
continue;
byte b0 = (byte) (Platform.getRandomInt() % 2 == 0 ? 1 : 0);
for (int i1 = 0; i1 < b0; ++i1)
{
for (int j1 = 0; j1 < b0; ++j1)
{
for (int k1 = 0; k1 < b0; ++k1)
{
double d0 = (double) target.blockX + ((double) i1 + 0.5D) / (double) b0;
double d1 = (double) target.blockY + ((double) j1 + 0.5D) / (double) b0;
double d2 = (double) target.blockZ + ((double) k1 + 0.5D) / (double) b0;
double dd0 = target.hitVec.xCoord;
double dd1 = target.hitVec.yCoord;
double dd2 = target.hitVec.zCoord;
EntityDiggingFX fx = (new EntityDiggingFX( world, dd0, dd1, dd2, d0 - (double) target.blockX - 0.5D, d1 - (double) target.blockY
- 0.5D, d2 - (double) target.blockZ - 0.5D, this, 0 )).applyColourMultiplier( target.blockX, target.blockY, target.blockZ );
fx.setParticleIcon( ico );
effectRenderer.addEffect( fx );
}
}
}
}
}
return true;
}
@SideOnly(Side.CLIENT)
public boolean addDestroyEffects(World world, int x, int y, int z, int meta, EffectRenderer effectRenderer)
{
Object pobj = cb( world, x, y, z );
if ( pobj instanceof IPartHost )
{
IPartHost host = (IPartHost) pobj;
for (ForgeDirection side : ForgeDirection.values())
{
IPart p = host.getPart( side );
IIcon ico = getIcon( p );
if ( ico == null )
continue;
byte b0 = 3;
for (int i1 = 0; i1 < b0; ++i1)
{
for (int j1 = 0; j1 < b0; ++j1)
{
for (int k1 = 0; k1 < b0; ++k1)
{
double d0 = (double) x + ((double) i1 + 0.5D) / (double) b0;
double d1 = (double) y + ((double) j1 + 0.5D) / (double) b0;
double d2 = (double) z + ((double) k1 + 0.5D) / (double) b0;
EntityDiggingFX fx = (new EntityDiggingFX( world, d0, d1, d2, d0 - (double) x - 0.5D, d1 - (double) y - 0.5D, d2 - (double) z
- 0.5D, this, meta )).applyColourMultiplier( x, y, z );
fx.setParticleIcon( ico );
effectRenderer.addEffect( fx );
}
}
}
}
}
return true;
}
private IIcon getIcon(IPart p)
{
if ( p == null )
return null;
try
{
IIcon ico = p.getBreakingTexture();
if ( ico != null )
return ico;
}
catch (Throwable t)
{
// nothing.
}
ItemStack is = p.getItemStack( PartItemStack.Network );
if ( is == null || is.getItem() == null )
return null;
return is.getItem().getIcon( is, 0 );
}
@Override @Override
public boolean canRenderInPass(int pass) public boolean canRenderInPass(int pass)
{ {
+3
View File
@@ -29,6 +29,9 @@ public class CableRenderHelper
TileEntity te = cableBusContainer.getTile(); TileEntity te = cableBusContainer.getTile();
RenderBlocksWorkaround renderer = BusRenderer.instance.renderer; RenderBlocksWorkaround renderer = BusRenderer.instance.renderer;
if ( renderer.overrideBlockTexture != null )
BusRenderHelper.instance.setPass( 0 );
if ( renderer.blockAccess == null ) if ( renderer.blockAccess == null )
renderer.blockAccess = Minecraft.getMinecraft().theWorld; renderer.blockAccess = Minecraft.getMinecraft().theWorld;
+50 -25
View File
@@ -13,6 +13,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items; import net.minecraft.init.Items;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon; import net.minecraft.util.IIcon;
import net.minecraft.world.World; import net.minecraft.world.World;
import appeng.api.AEApi; import appeng.api.AEApi;
@@ -22,6 +23,7 @@ import appeng.core.features.AEFeature;
import appeng.entity.EntityGrowingCrystal; import appeng.entity.EntityGrowingCrystal;
import appeng.entity.EntityIds; import appeng.entity.EntityIds;
import appeng.items.AEBaseItem; import appeng.items.AEBaseItem;
import appeng.util.Platform;
import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.common.registry.EntityRegistry;
public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
@@ -39,6 +41,29 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
IIcon fluix[] = new IIcon[3]; IIcon fluix[] = new IIcon[3];
IIcon nether[] = new IIcon[3]; IIcon nether[] = new IIcon[3];
private int getProgress(ItemStack is)
{
if ( is.hasTagCompound() )
{
return is.getTagCompound().getInteger( "progress" );
}
else
{
int progress;
NBTTagCompound comp = Platform.openNbtData( is );
comp.setInteger( "progress", progress = is.getItemDamage() );
is.setItemDamage( (is.getItemDamage() / SINGLE_OFFSET) * SINGLE_OFFSET );
return progress;
}
}
private void setProgress(ItemStack is, int newDamage)
{
NBTTagCompound comp = Platform.openNbtData( is );
comp.setInteger( "progress", newDamage );
is.setItemDamage( (is.getItemDamage() / SINGLE_OFFSET) * SINGLE_OFFSET );
}
public ItemCrystalSeed() { public ItemCrystalSeed() {
super( ItemCrystalSeed.class ); super( ItemCrystalSeed.class );
setHasSubtypes( true ); setHasSubtypes( true );
@@ -52,7 +77,7 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
@Override @Override
public String getUnlocalizedName(ItemStack is) public String getUnlocalizedName(ItemStack is)
{ {
int damage = is.getItemDamage(); int damage = getProgress( is );
if ( damage < Certus + SINGLE_OFFSET ) if ( damage < Certus + SINGLE_OFFSET )
return getUnlocalizedName() + ".Certus"; return getUnlocalizedName() + ".Certus";
@@ -69,7 +94,7 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
@Override @Override
public ItemStack triggerGrowth(ItemStack is) public ItemStack triggerGrowth(ItemStack is)
{ {
int newDamage = is.getItemDamage() + 1; int newDamage = getProgress( is ) + 1;
if ( newDamage == Certus + SINGLE_OFFSET ) if ( newDamage == Certus + SINGLE_OFFSET )
return AEApi.instance().materials().materialPureifiedCertusQuartzCrystal.stack( is.stackSize ); return AEApi.instance().materials().materialPureifiedCertusQuartzCrystal.stack( is.stackSize );
@@ -80,49 +105,43 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
if ( newDamage > END ) if ( newDamage > END )
return null; return null;
is.setItemDamage( newDamage ); setProgress( is, newDamage );
return is; return is;
} }
@Override @Override
public boolean isDamageable() public boolean isDamageable()
{ {
return true; return false;
} }
@Override @Override
public void addInformation(ItemStack stack, EntityPlayer p, List l, boolean b) public void addInformation(ItemStack stack, EntityPlayer p, List l, boolean b)
{ {
int progress = stack.getItemDamage() % 200; int progress = getProgress( stack ) % SINGLE_OFFSET;
l.add( Math.floor( (float) progress / 2.0f ) + "%" ); l.add( Math.floor( (float) progress / (float) (SINGLE_OFFSET / 100) ) + "%" );
super.addInformation( stack, p, l, b ); super.addInformation( stack, p, l, b );
} }
@Override @Override
public boolean isDamaged(ItemStack stack) public boolean isDamaged(ItemStack stack)
{ {
// if ( stack.getItemDamage() % 200 == 0 )
// return false;
return false; return false;
} }
@Override
public int getDisplayDamage(ItemStack stack)
{
return stack.getItemDamage() % 200;
}
@Override @Override
public int getMaxDamage(ItemStack stack) public int getMaxDamage(ItemStack stack)
{ {
return 200; return END;
} }
@Override @Override
public IIcon getIconFromDamage(int damage) public IIcon getIconIndex(ItemStack stack)
{ {
IIcon list[] = null; IIcon list[] = null;
int damage = getProgress( stack );
if ( damage < Certus + SINGLE_OFFSET ) if ( damage < Certus + SINGLE_OFFSET )
list = certus; list = certus;
@@ -198,19 +217,25 @@ public class ItemCrystalSeed extends AEBaseItem implements IGrowableCrystal
public void getSubItems(Item i, CreativeTabs t, List l) public void getSubItems(Item i, CreativeTabs t, List l)
{ {
// lvl 0 // lvl 0
l.add( new ItemStack( this, 1, Certus ) ); l.add( newStyle( new ItemStack( this, 1, Certus ) ) );
l.add( new ItemStack( this, 1, Nether ) ); l.add( newStyle( new ItemStack( this, 1, Nether ) ) );
l.add( new ItemStack( this, 1, Fluix ) ); l.add( newStyle( new ItemStack( this, 1, Fluix ) ) );
// lvl 1 // lvl 1
l.add( new ItemStack( this, 1, LEVEL_OFFSET + Certus ) ); l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + Certus ) ) );
l.add( new ItemStack( this, 1, LEVEL_OFFSET + Nether ) ); l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + Nether ) ) );
l.add( new ItemStack( this, 1, LEVEL_OFFSET + Fluix ) ); l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET + Fluix ) ) );
// lvl 2 // lvl 2
l.add( new ItemStack( this, 1, LEVEL_OFFSET * 2 + Certus ) ); l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + Certus ) ) );
l.add( new ItemStack( this, 1, LEVEL_OFFSET * 2 + Nether ) ); l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + Nether ) ) );
l.add( new ItemStack( this, 1, LEVEL_OFFSET * 2 + Fluix ) ); l.add( newStyle( new ItemStack( this, 1, LEVEL_OFFSET * 2 + Fluix ) ) );
}
private ItemStack newStyle(ItemStack itemStack)
{
getProgress( itemStack );
return itemStack;
} }
} }
+236 -238
View File
@@ -1,238 +1,236 @@
package appeng.me; package appeng.me;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import appeng.api.AEApi; import appeng.api.AEApi;
import appeng.api.networking.IGrid; import appeng.api.networking.IGrid;
import appeng.api.networking.IGridCache; 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.IMachineSet; import appeng.api.networking.IMachineSet;
import appeng.api.networking.events.MENetworkEvent; import appeng.api.networking.events.MENetworkEvent;
import appeng.api.networking.events.MENetworkPostCacheConstruction; import appeng.api.networking.events.MENetworkPostCacheConstruction;
import appeng.api.util.IReadOnlyCollection; import appeng.api.util.IReadOnlyCollection;
import appeng.core.WorldSettings; import appeng.core.WorldSettings;
import appeng.hooks.TickHandler; import appeng.hooks.TickHandler;
import appeng.util.ReadOnlyCollection; import appeng.util.ReadOnlyCollection;
public class Grid implements IGrid public class Grid implements IGrid
{ {
GridStorage myStorage; GridStorage myStorage;
NetworkEventBus bus = new NetworkEventBus(); NetworkEventBus bus = new NetworkEventBus();
HashMap<Class<? extends IGridHost>, Set> Machines = new HashMap<Class<? extends IGridHost>, Set>(); HashMap<Class<? extends IGridHost>, Set> Machines = new HashMap<Class<? extends IGridHost>, Set>();
HashMap<Class<? extends IGridCache>, GridCacheWrapper> caches = new HashMap<Class<? extends IGridCache>, GridCacheWrapper>(); HashMap<Class<? extends IGridCache>, GridCacheWrapper> caches = new HashMap<Class<? extends IGridCache>, GridCacheWrapper>();
GridNode pivot; GridNode pivot;
int isImportant; // how import is this network? int isImportant; // how import is this network?
public Grid(GridNode center) { public Grid(GridNode center) {
this.pivot = center; this.pivot = center;
HashMap<Class<? extends IGridCache>, IGridCache> myCaches = AEApi.instance().registries().gridCache().createCacheInstance( this ); HashMap<Class<? extends IGridCache>, IGridCache> myCaches = AEApi.instance().registries().gridCache().createCacheInstance( this );
for (Class<? extends IGridCache> c : myCaches.keySet()) for (Class<? extends IGridCache> c : myCaches.keySet())
{ {
bus.readClass( c, myCaches.get( c ).getClass() ); bus.readClass( c, myCaches.get( c ).getClass() );
caches.put( c, new GridCacheWrapper( myCaches.get( c ) ) ); caches.put( c, new GridCacheWrapper( myCaches.get( c ) ) );
} }
TickHandler.instance.addNetwork( this ); TickHandler.instance.addNetwork( this );
center.setGrid( this ); center.setGrid( this );
postEvent( new MENetworkPostCacheConstruction() ); postEvent( new MENetworkPostCacheConstruction() );
} }
public Set<Class<? extends IGridHost>> getMachineClasses() public Set<Class<? extends IGridHost>> getMachineClasses()
{ {
return Machines.keySet(); return Machines.keySet();
} }
@Override @Override
public IGridNode getPivot() public IGridNode getPivot()
{ {
return pivot; return pivot;
} }
public int size() public int size()
{ {
int out = 0; int out = 0;
for (Collection<?> x : Machines.values()) for (Collection<?> x : Machines.values())
out += x.size(); out += x.size();
return out; return out;
} }
public void remove(GridNode gridNode) public void remove(GridNode gridNode)
{ {
for (IGridCache c : caches.values()) for (IGridCache c : caches.values())
c.removeNode( gridNode, gridNode.getMachine() ); c.removeNode( gridNode, gridNode.getMachine() );
Collection<IGridNode> nodes = Machines.get( gridNode.getMachineClass() ); Collection<IGridNode> nodes = Machines.get( gridNode.getMachineClass() );
if ( nodes != null ) if ( nodes != null )
nodes.remove( gridNode ); nodes.remove( gridNode );
gridNode.setGridStorage( null ); gridNode.setGridStorage( null );
if ( pivot == gridNode ) if ( pivot == gridNode )
{ {
Iterator<IGridNode> n = getNodes().iterator(); Iterator<IGridNode> n = getNodes().iterator();
if ( n.hasNext() ) if ( n.hasNext() )
pivot = (GridNode) n.next(); pivot = (GridNode) n.next();
else else
{ {
pivot = null; pivot = null;
TickHandler.instance.removeNetwork( this ); TickHandler.instance.removeNetwork( this );
myStorage.remove(); myStorage.remove();
} }
} }
} }
public void add(GridNode gridNode) public void add(GridNode gridNode)
{ {
Class<? extends IGridHost> mClass = gridNode.getMachineClass(); Class<? extends IGridHost> mClass = gridNode.getMachineClass();
Set<IGridNode> nodes = Machines.get( mClass ); Set<IGridNode> nodes = Machines.get( mClass );
if ( nodes == null ) if ( nodes == null )
{ {
Machines.put( mClass, nodes = new MachineSet( mClass ) ); Machines.put( mClass, nodes = new MachineSet( mClass ) );
bus.readClass( mClass, mClass ); bus.readClass( mClass, mClass );
} }
// handle loading grid storages. // handle loading grid storages.
if ( gridNode.getGridStorage() != null ) if ( gridNode.getGridStorage() != null )
{ {
GridStorage gs = gridNode.getGridStorage(); GridStorage gs = gridNode.getGridStorage();
if ( gs.getGrid() == null ) if ( gs.getGrid() == null )
{ {
myStorage = gs; myStorage = gs;
myStorage.setGrid( this ); myStorage.setGrid( this );
for (IGridCache gc : caches.values()) for (IGridCache gc : caches.values())
gc.onJoin( myStorage ); gc.onJoin( myStorage );
} }
else if ( gs.getGrid() != this ) else if ( gs.getGrid() != this )
{ {
if ( myStorage == null ) if ( myStorage == null )
{ {
myStorage = WorldSettings.getInstance().getNewGridStorage(); myStorage = WorldSettings.getInstance().getNewGridStorage();
myStorage.setGrid( this ); myStorage.setGrid( this );
} }
GridStorage tmp = new GridStorage(); GridStorage tmp = new GridStorage();
if ( !gs.hasDivided( myStorage ) ) if ( !gs.hasDivided( myStorage ) )
{ {
gs.addDivided( myStorage ); gs.addDivided( myStorage );
for (IGridCache gc : ((Grid) gs.getGrid()).caches.values()) for (IGridCache gc : ((Grid) gs.getGrid()).caches.values())
gc.onSplit( tmp ); gc.onSplit( tmp );
for (IGridCache gc : caches.values()) for (IGridCache gc : caches.values())
gc.onJoin( tmp ); gc.onJoin( tmp );
} }
} }
} }
else if ( myStorage == null ) else if ( myStorage == null )
{ {
myStorage = WorldSettings.getInstance().getNewGridStorage(); myStorage = WorldSettings.getInstance().getNewGridStorage();
myStorage.setGrid( this ); myStorage.setGrid( this );
} }
// update grid node... // update grid node...
gridNode.setGridStorage( myStorage ); gridNode.setGridStorage( myStorage );
// track node. // track node.
nodes.add( gridNode ); nodes.add( gridNode );
for (IGridCache c : caches.values()) for (IGridCache c : caches.values())
c.addNode( gridNode, gridNode.getMachine() ); c.addNode( gridNode, gridNode.getMachine() );
gridNode.gridProxy.gridChanged(); gridNode.gridProxy.gridChanged();
// postEventTo( gridNode, networkChanged ); // postEventTo( gridNode, networkChanged );
} }
@Override @Override
public IReadOnlyCollection<IGridNode> getNodes() public IReadOnlyCollection<IGridNode> getNodes()
{ {
return new NodeIteratable( Machines ); return new NodeIteratable( Machines );
} }
@Override @Override
public IReadOnlyCollection<Class<? extends IGridHost>> getMachinesClasses() public IReadOnlyCollection<Class<? extends IGridHost>> getMachinesClasses()
{ {
return new ReadOnlyCollection<Class<? extends IGridHost>>( Machines.keySet() ); return new ReadOnlyCollection<Class<? extends IGridHost>>( Machines.keySet() );
} }
@Override @Override
public IMachineSet getMachines(Class<? extends IGridHost> c) public IMachineSet getMachines(Class<? extends IGridHost> c)
{ {
MachineSet s = (MachineSet) Machines.get( c ); MachineSet s = (MachineSet) Machines.get( c );
if ( s == null ) if ( s == null )
return new MachineSet( c ); return new MachineSet( c );
return s; return s;
} }
@Override @Override
public <C extends IGridCache> C getCache(Class<? extends IGridCache> iface) public <C extends IGridCache> C getCache(Class<? extends IGridCache> iface)
{ {
return (C) caches.get( iface ).myCache; return (C) caches.get( iface ).myCache;
} }
@Override @Override
public MENetworkEvent postEventTo(IGridNode node, MENetworkEvent ev) public MENetworkEvent postEventTo(IGridNode node, MENetworkEvent ev)
{ {
return bus.postEventTo( this, (GridNode) node, ev ); return bus.postEventTo( this, (GridNode) node, ev );
} }
@Override @Override
public MENetworkEvent postEvent(MENetworkEvent ev) public MENetworkEvent postEvent(MENetworkEvent ev)
{ {
return bus.postEvent( this, ev ); return bus.postEvent( this, ev );
} }
public void requestSave() public void requestSave()
{ {
myStorage.markDirty(); myStorage.markDirty();
WorldSettings.getInstance().save(); WorldSettings.getInstance().save();
} }
public void update() public void update()
{ {
// are ther any nodes left? for (IGridCache gc : caches.values())
if ( pivot != null ) {
{ // are there any nodes left?
for (IGridCache gc : caches.values()) if ( pivot != null )
{ gc.onUpdateTick();
gc.onUpdateTick(); }
} }
}
} public Iterable<GridCacheWrapper> getCacheWrappers()
{
public Iterable<GridCacheWrapper> getCacheWrappers() return caches.values();
{ }
return caches.values();
} @Override
public boolean isEmpty()
@Override {
public boolean isEmpty() return pivot == null;
{ }
return pivot == null;
} public void saveState()
{
public void saveState() for (IGridCache c : caches.values())
{ {
for (IGridCache c : caches.values()) c.populateGridStorage( myStorage );
{ }
c.populateGridStorage( myStorage ); }
}
} public void setImportantFlag(int i, boolean publicHasPower)
{
public void setImportantFlag(int i, boolean publicHasPower) int flag = 1 << i;
{ isImportant = (isImportant & ~flag) | (publicHasPower ? flag : 0);
int flag = 1 << i; }
isImportant = (isImportant & ~flag) | (publicHasPower ? flag : 0);
} }
}
+3 -1
View File
@@ -27,6 +27,7 @@ import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList; import appeng.api.storage.data.IItemList;
import appeng.me.helpers.StorageInterestManager;
import appeng.me.storage.ItemWatcher; import appeng.me.storage.ItemWatcher;
import appeng.me.storage.NetworkInventoryHandler; import appeng.me.storage.NetworkInventoryHandler;
@@ -36,7 +37,8 @@ import com.google.common.collect.SetMultimap;
public class GridStorageCache implements IStorageGrid public class GridStorageCache implements IStorageGrid
{ {
public SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create(); final private SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create();
final public StorageInterestManager interestManager = new StorageInterestManager( interests );
final HashSet<ICellProvider> activeCellProviders = new HashSet(); final HashSet<ICellProvider> activeCellProviders = new HashSet();
final HashSet<ICellProvider> inactiveCellProviders = new HashSet(); final HashSet<ICellProvider> inactiveCellProviders = new HashSet();
+7 -3
View File
@@ -59,9 +59,9 @@ public class NetworkMonitor<T extends IAEStack<T>> extends MEMonitorHandler<T>
sendEvent = true; sendEvent = true;
super.postChange( diff, src ); super.postChange( diff, src );
if ( myGridCache.interests.containsKey( diff ) ) if ( myGridCache.interestManager.containsKey( diff ) )
{ {
Set<ItemWatcher> list = myGridCache.interests.get( diff ); Set<ItemWatcher> list = myGridCache.interestManager.get( diff );
if ( !list.isEmpty() ) if ( !list.isEmpty() )
{ {
IItemList<T> myStorageList = getStorageList(); IItemList<T> myStorageList = getStorageList();
@@ -72,9 +72,13 @@ public class NetworkMonitor<T extends IAEStack<T>> extends MEMonitorHandler<T>
fullStack = diff.copy(); fullStack = diff.copy();
fullStack.setStackSize( 0 ); fullStack.setStackSize( 0 );
} }
myGridCache.interestManager.enableTransactions();
for (ItemWatcher iw : list) for (ItemWatcher iw : list)
iw.getHost().onStackChange( myStorageList, fullStack, diff, src, getChannel() ); iw.getHost().onStackChange( myStorageList, fullStack, diff, src, getChannel() );
myGridCache.interestManager.disableTransactions();
} }
} }
+84
View File
@@ -0,0 +1,84 @@
package appeng.me.helpers;
import java.util.LinkedList;
import java.util.Set;
import appeng.api.storage.data.IAEStack;
import appeng.me.storage.ItemWatcher;
import com.google.common.collect.SetMultimap;
public class StorageInterestManager {
class SavedTransactions {
public final boolean put;
public final IAEStack stack;
public final ItemWatcher iw;
public SavedTransactions( boolean putOperation, IAEStack myStack, ItemWatcher watcher )
{
put = putOperation;
stack = myStack;
iw = watcher;
}
};
private final SetMultimap<IAEStack, ItemWatcher> container;
private LinkedList<SavedTransactions> transactions = null;
public StorageInterestManager(SetMultimap<IAEStack, ItemWatcher> interests) {
container = interests;
}
public void enableTransactions()
{
transactions = new LinkedList();
}
public void disableTransactions()
{
LinkedList<SavedTransactions> myActions = transactions;
transactions = null;
for ( SavedTransactions t : myActions )
{
if ( t.put )
put( t.stack, t.iw );
else
remove( t.stack, t.iw );
}
}
public boolean containsKey( IAEStack stack )
{
return container.containsKey( stack );
}
public Set<ItemWatcher> get( IAEStack stack )
{
return container.get( stack );
}
public boolean put( IAEStack stack, ItemWatcher iw )
{
if ( transactions != null )
{
transactions.add( new SavedTransactions( true, stack, iw ) );
return true;
}
else
return container.put( stack, iw );
}
public boolean remove( IAEStack stack, ItemWatcher iw )
{
if ( transactions != null )
{
transactions.add( new SavedTransactions( true, stack, iw ) );
return true;
}
else
return container.remove( stack, iw );
}
}
+4 -4
View File
@@ -42,7 +42,7 @@ public class ItemWatcher implements IStackWatcher
@Override @Override
public void remove() public void remove()
{ {
gsc.interests.remove( myLast, watcher ); gsc.interestManager.remove( myLast, watcher );
interestIterator.remove(); interestIterator.remove();
} }
@@ -68,7 +68,7 @@ public class ItemWatcher implements IStackWatcher
if ( myInterests.contains( e ) ) if ( myInterests.contains( e ) )
return false; return false;
return myInterests.add( e.copy() ) && gsc.interests.put( e, this ); return myInterests.add( e.copy() ) && gsc.interestManager.put( e, this );
} }
@Override @Override
@@ -88,7 +88,7 @@ public class ItemWatcher implements IStackWatcher
Iterator<IAEStack> i = myInterests.iterator(); Iterator<IAEStack> i = myInterests.iterator();
while (i.hasNext()) while (i.hasNext())
{ {
gsc.interests.remove( i.next(), this ); gsc.interestManager.remove( i.next(), this );
i.remove(); i.remove();
} }
} }
@@ -120,7 +120,7 @@ public class ItemWatcher implements IStackWatcher
@Override @Override
public boolean remove(Object o) public boolean remove(Object o)
{ {
return myInterests.remove( o ) && gsc.interests.remove( o, this ); return myInterests.remove( o ) && gsc.interestManager.remove( (IAEStack)o, this );
} }
@Override @Override
+7
View File
@@ -16,6 +16,7 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.Vec3; import net.minecraft.util.Vec3;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
@@ -500,4 +501,10 @@ public class AEBasePart implements IPart, IGridProxyable, IActionHost, IUpgradea
return is.hasDisplayName(); return is.hasDisplayName();
} }
@Override
@SideOnly(Side.CLIENT)
public IIcon getBreakingTexture()
{
return null;
}
} }
-1
View File
@@ -434,7 +434,6 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
bch.addBox( 6.0, 6.0, 6.0, 10.0, 10.0, 10.0 ); bch.addBox( 6.0, 6.0, 6.0, 10.0, 10.0, 10.0 );
else else
part.getBoxes( bch ); part.getBoxes( bch );
} }
if ( includeFacades && s != null && s != ForgeDirection.UNKNOWN ) if ( includeFacades && s != null && s != ForgeDirection.UNKNOWN )
+7
View File
@@ -7,6 +7,7 @@ import java.io.IOException;
import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.implementations.IPowerChannelState; import appeng.api.implementations.IPowerChannelState;
import appeng.api.networking.GridFlags; import appeng.api.networking.GridFlags;
@@ -129,4 +130,10 @@ public class PartBasicState extends AEBasePart implements IPowerChannelState
return (clientFlags & CHANNEL_FLAG) == CHANNEL_FLAG; return (clientFlags & CHANNEL_FLAG) == CHANNEL_FLAG;
} }
@Override
@SideOnly(Side.CLIENT)
public IIcon getBreakingTexture()
{
return CableBusTextures.PartTransitionPlaneBack.getIcon();
}
} }
+4 -1
View File
@@ -27,6 +27,9 @@ import appeng.core.sync.GuiBridge;
import appeng.me.GridAccessException; import appeng.me.GridAccessException;
import appeng.util.InventoryAdaptor; import appeng.util.InventoryAdaptor;
import appeng.util.Platform; import appeng.util.Platform;
import com.google.common.collect.ImmutableList;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@@ -166,7 +169,7 @@ public class PartExportBus extends PartSharedItemBus implements IGridTickable
if ( getInstalledUpgrades( Upgrades.FUZZY ) > 0 ) if ( getInstalledUpgrades( Upgrades.FUZZY ) > 0 )
{ {
for (IAEItemStack o : inv.getStorageList().findFuzzy( ais, fzMode )) for (IAEItemStack o : ImmutableList.copyOf( inv.getStorageList().findFuzzy( ais, fzMode ) ))
{ {
pushItemIntoTarget( d, energy, fzMode, inv, o ); pushItemIntoTarget( d, energy, fzMode, inv, o );
if ( itemToSend <= 0 ) if ( itemToSend <= 0 )
+6
View File
@@ -531,6 +531,12 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH
// super.renderWorldBlock( world, x, y, z, block, modelId, renderer ); // super.renderWorldBlock( world, x, y, z, block, modelId, renderer );
} }
@Override
public IIcon getBreakingTexture()
{
return is.getIconIndex();
}
@Override @Override
public void getBoxes(IPartCollsionHelper bch) public void getBoxes(IPartCollsionHelper bch)
{ {
+6
View File
@@ -230,4 +230,10 @@ public class PartCableAnchor implements IPart
{ {
return what == BusSupport.CABLE || what == BusSupport.DENSE_CABLE; return what == BusSupport.CABLE || what == BusSupport.DENSE_CABLE;
} }
@Override
public IIcon getBreakingTexture()
{
return null;
}
} }
+7
View File
@@ -11,6 +11,7 @@ import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.Vec3; import net.minecraft.util.Vec3;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.implementations.tiles.ISegmentedInventory; import appeng.api.implementations.tiles.ISegmentedInventory;
@@ -131,6 +132,12 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISeg
renderLights( x, y, z, rh, renderer ); renderLights( x, y, z, rh, renderer );
} }
@Override
public IIcon getBreakingTexture()
{
return is.getIconIndex();
}
@Override @Override
public void getBoxes(IPartCollsionHelper bch) public void getBoxes(IPartCollsionHelper bch)
{ {
+7
View File
@@ -9,6 +9,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
@@ -186,6 +187,12 @@ public class PartToggleBus extends PartBasicState
renderLights( x, y, z, rh, renderer ); renderLights( x, y, z, rh, renderer );
} }
@Override
public IIcon getBreakingTexture()
{
return is.getIconIndex();
}
@Override @Override
public void getBoxes(IPartCollsionHelper bch) public void getBoxes(IPartCollsionHelper bch)
{ {
+47
View File
@@ -330,6 +330,46 @@ public class PartCable extends AEBasePart implements IPartCable
connections.clear(); connections.clear();
} }
IPartHost ph = getHost();
if ( ph != null )
{
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
IPart p = ph.getPart( dir );
if ( p instanceof IGridHost )
{
double dist = p.cableConnectionRenderTo();
if ( dist > 8 )
continue;
switch (dir)
{
case DOWN:
bch.addBox( 6.0, dist, 6.0, 10.0, 6.0, 10.0 );
break;
case EAST:
bch.addBox( 10.0, 6.0, 6.0, 16.0 - dist, 10.0, 10.0 );
break;
case NORTH:
bch.addBox( 6.0, 6.0, dist, 10.0, 10.0, 6.0 );
break;
case SOUTH:
bch.addBox( 6.0, 6.0, 10.0, 10.0, 10.0, 16.0 - dist );
break;
case UP:
bch.addBox( 6.0, 10.0, 6.0, 10.0, 16.0 - dist, 10.0 );
break;
case WEST:
bch.addBox( dist, 6.0, 6.0, 6.0, 10.0, 10.0 );
break;
default:
continue;
}
}
}
}
for (ForgeDirection of : connections) for (ForgeDirection of : connections)
{ {
switch (of) switch (of)
@@ -370,6 +410,13 @@ public class PartCable extends AEBasePart implements IPartCable
rh.setTexture( null ); rh.setTexture( null );
} }
@Override
@SideOnly(Side.CLIENT)
public IIcon getBreakingTexture()
{
return getTexture( getCableColor() );
}
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void rendereGlassConection(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer, ForgeDirection of) public void rendereGlassConection(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer, ForgeDirection of)
{ {
+7
View File
@@ -331,6 +331,13 @@ public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
renderLights( x, y, z, rh, renderer ); renderLights( x, y, z, rh, renderer );
} }
@Override
@SideOnly(Side.CLIENT)
public IIcon getBreakingTexture()
{
return CableBusTextures.BlockP2PTunnel2.getIcon();
}
protected void QueueTunnelDrain(PowerUnits unit, double f) protected void QueueTunnelDrain(PowerUnits unit, double f)
{ {
double ae_to_tax = unit.convertTo( PowerUnits.AE, f * AEConfig.TunnelPowerLoss ); double ae_to_tax = unit.convertTo( PowerUnits.AE, f * AEConfig.TunnelPowerLoss );
+3 -1
View File
@@ -13,6 +13,8 @@ import appeng.api.storage.data.IItemList;
import appeng.util.InventoryAdaptor; import appeng.util.InventoryAdaptor;
import appeng.util.item.AEItemStack; import appeng.util.item.AEItemStack;
import com.google.common.collect.ImmutableList;
public class IMEAdaptor extends InventoryAdaptor public class IMEAdaptor extends InventoryAdaptor
{ {
@@ -44,7 +46,7 @@ public class IMEAdaptor extends InventoryAdaptor
IAEItemStack out = null; IAEItemStack out = null;
for (IAEItemStack req : getList().findFuzzy( reqFilter, fuzzyMode )) for (IAEItemStack req : ImmutableList.copyOf( getList().findFuzzy( reqFilter, fuzzyMode ) ))
{ {
if ( req != null ) if ( req != null )
{ {