Basic reformat, hit once, hope never again

This commit is contained in:
thatsIch
2015-04-03 08:54:31 +02:00
parent 4ff1631f89
commit d34c988c88
886 changed files with 31400 additions and 30990 deletions
@@ -18,13 +18,18 @@
package appeng.helpers;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
public class AEGlassMaterial extends Material
{
public AEGlassMaterial(MapColor p_i2116_1_) {
public static final AEGlassMaterial INSTANCE = ( new AEGlassMaterial( MapColor.airColor ) );
public AEGlassMaterial( MapColor p_i2116_1_ )
{
super( p_i2116_1_ );
}
@@ -33,7 +38,4 @@ public class AEGlassMaterial extends Material
{
return false;
}
public static final AEGlassMaterial INSTANCE = (new AEGlassMaterial( MapColor.airColor ));
}
@@ -18,10 +18,12 @@
package appeng.helpers;
import appeng.api.implementations.tiles.IColorableTile;
import appeng.api.networking.IGridHost;
import appeng.api.parts.IPartHost;
public interface AEMultiTile extends IGridHost, IPartHost, IColorableTile
{
File diff suppressed because it is too large Load Diff
@@ -18,12 +18,14 @@
package appeng.helpers;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.BaseActionSource;
public interface IContainerCraftingPacket
{
@@ -34,9 +36,10 @@ public interface IContainerCraftingPacket
/**
* @param string name of inventory
*
* @return the inventory of the part/tile by name.
*/
IInventory getInventoryByName(String string);
IInventory getInventoryByName( String string );
/**
* @return who are we?
@@ -52,5 +55,4 @@ public interface IContainerCraftingPacket
* @return array of view cells
*/
ItemStack[] getViewCells();
}
@@ -18,15 +18,17 @@
package appeng.helpers;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
public interface ICustomCollision
{
Iterable<AxisAlignedBB> getSelectedBoundingBoxesFromPool(World w, int x, int y, int z, Entity thePlayer, boolean b);
Iterable<AxisAlignedBB> getSelectedBoundingBoxesFromPool( World w, int x, int y, int z, Entity thePlayer, boolean b );
void addCollidingBlockToList(World w, int x, int y, int z, AxisAlignedBB bb, List<AxisAlignedBB> out, Entity e);
void addCollidingBlockToList( World w, int x, int y, int z, AxisAlignedBB bb, List<AxisAlignedBB> out, Entity e );
}
@@ -18,11 +18,11 @@
package appeng.helpers;
public interface ICustomNameObject
{
String getCustomName();
boolean hasCustomName();
}
@@ -18,6 +18,7 @@
package appeng.helpers;
import java.util.EnumSet;
import net.minecraft.tileentity.TileEntity;
@@ -27,6 +28,7 @@ import appeng.api.implementations.IUpgradeableHost;
import appeng.api.networking.crafting.ICraftingProvider;
import appeng.api.networking.crafting.ICraftingRequester;
public interface IInterfaceHost extends ICraftingProvider, IUpgradeableHost, ICraftingRequester
{
@@ -18,11 +18,12 @@
package appeng.helpers;
import net.minecraft.item.ItemStack;
public interface IMouseWheelItem
{
void onWheel(ItemStack is, boolean up);
void onWheel( ItemStack is, boolean up );
}
@@ -18,6 +18,7 @@
package appeng.helpers;
public interface IPriorityHost
{
@@ -29,6 +30,5 @@ public interface IPriorityHost
/**
* set new priority
*/
void setPriority(int newValue);
void setPriority( int newValue );
}
@@ -18,6 +18,7 @@
package appeng.helpers;
public enum InventoryAction
{
// standard vanilla mechanics.
@@ -18,11 +18,13 @@
package appeng.helpers;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.util.IOrientable;
public class LocationRotation implements IOrientable
{
@@ -31,7 +33,8 @@ public class LocationRotation implements IOrientable
final int y;
final int z;
public LocationRotation(IBlockAccess world, int x, int y, int z) {
public LocationRotation( IBlockAccess world, int x, int y, int z )
{
this.w = world;
this.x = x;
this.y = y;
@@ -39,9 +42,17 @@ public class LocationRotation implements IOrientable
}
@Override
public void setOrientation(ForgeDirection Forward, ForgeDirection Up)
public boolean canBeRotated()
{
return false;
}
@Override
public ForgeDirection getForward()
{
if( this.getUp().offsetY == 0 )
return ForgeDirection.UP;
return ForgeDirection.SOUTH;
}
@Override
@@ -52,16 +63,8 @@ public class LocationRotation implements IOrientable
}
@Override
public ForgeDirection getForward()
public void setOrientation( ForgeDirection Forward, ForgeDirection Up )
{
if ( this.getUp().offsetY == 0 )
return ForgeDirection.UP;
return ForgeDirection.SOUTH;
}
@Override
public boolean canBeRotated()
{
return false;
}
}
+19 -16
View File
@@ -18,12 +18,14 @@
package appeng.helpers;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.util.IOrientable;
public class MetaRotation implements IOrientable
{
@@ -32,7 +34,8 @@ public class MetaRotation implements IOrientable
final int y;
final int z;
public MetaRotation(IBlockAccess world, int x, int y, int z) {
public MetaRotation( IBlockAccess world, int x, int y, int z )
{
this.w = world;
this.x = x;
this.y = y;
@@ -40,12 +43,17 @@ public class MetaRotation implements IOrientable
}
@Override
public void setOrientation(ForgeDirection Forward, ForgeDirection Up)
public boolean canBeRotated()
{
if ( this.w instanceof World )
((World) this.w).setBlockMetadataWithNotify( this.x, this.y, this.z, Up.ordinal(), 1 + 2 );
else
throw new RuntimeException( this.w.getClass().getName() + " received, expected World" );
return true;
}
@Override
public ForgeDirection getForward()
{
if( this.getUp().offsetY == 0 )
return ForgeDirection.UP;
return ForgeDirection.SOUTH;
}
@Override
@@ -55,16 +63,11 @@ public class MetaRotation implements IOrientable
}
@Override
public ForgeDirection getForward()
public void setOrientation( ForgeDirection Forward, ForgeDirection Up )
{
if ( this.getUp().offsetY == 0 )
return ForgeDirection.UP;
return ForgeDirection.SOUTH;
}
@Override
public boolean canBeRotated()
{
return true;
if( this.w instanceof World )
( (World) this.w ).setBlockMetadataWithNotify( this.x, this.y, this.z, Up.ordinal(), 1 + 2 );
else
throw new RuntimeException( this.w.getClass().getName() + " received, expected World" );
}
}
@@ -18,14 +18,15 @@
package appeng.helpers;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import com.google.common.collect.ImmutableSet;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import com.google.common.collect.ImmutableSet;
import appeng.api.AEApi;
import appeng.api.networking.IGrid;
import appeng.api.networking.crafting.ICraftingGrid;
@@ -37,6 +38,7 @@ import appeng.api.storage.data.IAEItemStack;
import appeng.parts.automation.NonNullArrayIterator;
import appeng.util.InventoryAdaptor;
public class MultiCraftingTracker
{
@@ -46,27 +48,50 @@ public class MultiCraftingTracker
Future<ICraftingJob>[] jobs = null;
ICraftingLink[] links = null;
public MultiCraftingTracker(ICraftingRequester o, int size) {
public MultiCraftingTracker( ICraftingRequester o, int size )
{
this.owner = o;
this.size = size;
}
public void readFromNBT(NBTTagCompound extra)
public void readFromNBT( NBTTagCompound extra )
{
for (int x = 0; x < this.size; x++)
for( int x = 0; x < this.size; x++ )
{
NBTTagCompound link = extra.getCompoundTag( "links-" + x );
if ( link != null && !link.hasNoTags() )
if( link != null && !link.hasNoTags() )
this.setLink( x, AEApi.instance().storage().loadCraftingLink( link, this.owner ) );
}
}
public void writeToNBT(NBTTagCompound extra)
void setLink( int slot, ICraftingLink l )
{
for (int x = 0; x < this.size; x++)
if( this.links == null )
this.links = new ICraftingLink[this.size];
this.links[slot] = l;
boolean hasStuff = false;
for( int x = 0; x < this.links.length; x++ )
{
ICraftingLink g = this.links[x];
if( g == null || g.isCanceled() || g.isDone() )
this.links[x] = null;
else
hasStuff = true;
}
if( !hasStuff )
this.links = null;
}
public void writeToNBT( NBTTagCompound extra )
{
for( int x = 0; x < this.size; x++ )
{
ICraftingLink link = this.getLink( x );
if ( link != null )
if( link != null )
{
NBTTagCompound ln = new NBTTagCompound();
link.writeToNBT( ln );
@@ -75,42 +100,50 @@ public class MultiCraftingTracker
}
}
public boolean handleCrafting(int x, long itemToCraft, IAEItemStack ais, InventoryAdaptor d, World w, IGrid g, ICraftingGrid cg, BaseActionSource mySrc)
ICraftingLink getLink( int slot )
{
if ( ais != null && d.simulateAdd( ais.getItemStack() ) == null )
if( this.links == null )
return null;
return this.links[slot];
}
public boolean handleCrafting( int x, long itemToCraft, IAEItemStack ais, InventoryAdaptor d, World w, IGrid g, ICraftingGrid cg, BaseActionSource mySrc )
{
if( ais != null && d.simulateAdd( ais.getItemStack() ) == null )
{
Future<ICraftingJob> craftingJob = this.getJob( x );
if ( this.getLink( x ) != null )
if( this.getLink( x ) != null )
{
return false;
}
else if ( craftingJob != null )
else if( craftingJob != null )
{
ICraftingJob job = null;
try
{
if ( craftingJob.isDone() )
if( craftingJob.isDone() )
job = craftingJob.get();
if ( job != null )
if( job != null )
{
this.setJob( x, null );
this.setLink( x, cg.submitJob( job, this.owner, null, false, mySrc ) );
return true;
}
}
catch (InterruptedException e)
catch( InterruptedException e )
{
// :P
}
catch (ExecutionException e)
catch( ExecutionException e )
{
// :P
}
}
else
{
if ( this.getLink( x ) == null )
if( this.getLink( x ) == null )
{
IAEItemStack aisC = ais.copy();
aisC.setStackSize( itemToCraft );
@@ -121,79 +154,49 @@ public class MultiCraftingTracker
return false;
}
ICraftingLink getLink(int slot)
Future<ICraftingJob> getJob( int slot )
{
if ( this.links == null )
return null;
return this.links[slot];
}
void setLink(int slot, ICraftingLink l)
{
if ( this.links == null )
this.links = new ICraftingLink[this.size];
this.links[slot] = l;
boolean hasStuff = false;
for (int x = 0; x < this.links.length; x++)
{
ICraftingLink g = this.links[x];
if ( g == null || g.isCanceled() || g.isDone() )
this.links[x] = null;
else
hasStuff = true;
}
if ( !hasStuff )
this.links = null;
}
Future<ICraftingJob> getJob(int slot)
{
if ( this.jobs == null )
if( this.jobs == null )
return null;
return this.jobs[slot];
}
void setJob(int slot, Future<ICraftingJob> l)
void setJob( int slot, Future<ICraftingJob> l )
{
if ( this.jobs == null )
if( this.jobs == null )
this.jobs = new Future[this.size];
this.jobs[slot] = l;
boolean hasStuff = false;
for (Future<ICraftingJob> job : this.jobs)
for( Future<ICraftingJob> job : this.jobs )
{
if ( job != null )
if( job != null )
{
hasStuff = true;
}
}
if ( !hasStuff )
if( !hasStuff )
this.jobs = null;
}
public ImmutableSet<ICraftingLink> getRequestedJobs()
{
if ( this.links == null )
if( this.links == null )
return ImmutableSet.of();
return ImmutableSet.copyOf( new NonNullArrayIterator( this.links ) );
}
public void jobStateChange(ICraftingLink link)
public void jobStateChange( ICraftingLink link )
{
if ( this.links != null )
if( this.links != null )
{
for (int x = 0; x < this.links.length; x++)
for( int x = 0; x < this.links.length; x++ )
{
if ( this.links[x] == link )
if( this.links[x] == link )
{
this.setLink( x, null );
return;
@@ -202,13 +205,13 @@ public class MultiCraftingTracker
}
}
public int getSlot(ICraftingLink link)
public int getSlot( ICraftingLink link )
{
if ( this.links != null )
if( this.links != null )
{
for (int x = 0; x < this.links.length; x++)
for( int x = 0; x < this.links.length; x++ )
{
if ( this.links[x] == link )
if( this.links[x] == link )
return x;
}
}
@@ -218,22 +221,22 @@ public class MultiCraftingTracker
public void cancel()
{
if ( this.links != null )
if( this.links != null )
{
for (ICraftingLink l : this.links)
for( ICraftingLink l : this.links )
{
if ( l != null )
if( l != null )
l.cancel();
}
this.links = null;
}
if ( this.jobs != null )
if( this.jobs != null )
{
for (Future<ICraftingJob> l : this.jobs)
for( Future<ICraftingJob> l : this.jobs )
{
if ( l != null )
if( l != null )
l.cancel( true );
}
@@ -241,7 +244,7 @@ public class MultiCraftingTracker
}
}
public boolean isBusy(int slot)
public boolean isBusy( int slot )
{
return this.getLink( slot ) != null || this.getJob( slot ) != null;
}
+13 -10
View File
@@ -18,27 +18,24 @@
package appeng.helpers;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.util.IOrientable;
public class NullRotation implements IOrientable
{
public NullRotation() {
}
@Override
public void setOrientation(ForgeDirection Forward, ForgeDirection Up)
public NullRotation()
{
}
@Override
public ForgeDirection getUp()
public boolean canBeRotated()
{
return ForgeDirection.UP;
return false;
}
@Override
@@ -48,8 +45,14 @@ public class NullRotation implements IOrientable
}
@Override
public boolean canBeRotated()
public ForgeDirection getUp()
{
return false;
return ForgeDirection.UP;
}
@Override
public void setOrientation( ForgeDirection Forward, ForgeDirection Up )
{
}
}
+168 -172
View File
@@ -41,113 +41,30 @@ import appeng.util.ItemSorters;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
public class PatternHelper implements ICraftingPatternDetails, Comparable<PatternHelper>
{
final ItemStack patternItem;
private final IAEItemStack pattern;
final InventoryCrafting crafting = new InventoryCrafting( new ContainerNull(), 3, 3 );
final InventoryCrafting testFrame = new InventoryCrafting( new ContainerNull(), 3, 3 );
final ItemStack correctOutput;
final IRecipe standardRecipe;
final IAEItemStack[] condensedInputs;
final IAEItemStack[] condensedOutputs;
final IAEItemStack[] inputs;
final IAEItemStack[] outputs;
final boolean isCrafting;
public int priority = 0;
static class TestLookup
{
final int slot;
final int ref;
final int hash;
public TestLookup(int slot, ItemStack i)
{
this( slot, i.getItem(), i.getItemDamage() );
}
public TestLookup(int slot, Item item, int dmg)
{
this.slot = slot;
this.ref = (dmg << Platform.DEF_OFFSET) | (Item.getIdFromItem( item ) & 0xffff);
int offset = 3 * slot;
this.hash = (this.ref << offset) | (this.ref >> (offset + 32));
}
@Override
public int hashCode()
{
return this.hash;
}
@Override
public boolean equals(Object obj)
{
final boolean equality;
if ( obj instanceof TestLookup )
{
TestLookup b = (TestLookup) obj;
equality = b.slot == this.slot && b.ref == this.ref;
}
else
{
equality = false;
}
return equality;
}
}
enum TestStatus
{
ACCEPT, DECLINE, TEST
}
final HashSet<TestLookup> failCache = new HashSet<TestLookup>();
final HashSet<TestLookup> passCache = new HashSet<TestLookup>();
private final IAEItemStack pattern;
public int priority = 0;
private void markItemAs(int slotIndex, ItemStack i, TestStatus b)
{
if ( b == TestStatus.TEST || i.hasTagCompound() )
return;
(b == TestStatus.ACCEPT ? this.passCache : this.failCache).add( new TestLookup( slotIndex, i ) );
}
private TestStatus getStatus(int slotIndex, ItemStack i)
{
if ( this.crafting.getStackInSlot( slotIndex ) == null )
return i == null ? TestStatus.ACCEPT : TestStatus.DECLINE;
if ( i == null )
return TestStatus.DECLINE;
if ( i.hasTagCompound() )
return TestStatus.TEST;
if ( this.passCache.contains( new TestLookup( slotIndex, i ) ) )
return TestStatus.ACCEPT;
if ( this.failCache.contains( new TestLookup( slotIndex, i ) ) )
return TestStatus.DECLINE;
return TestStatus.TEST;
}
public PatternHelper(ItemStack is, World w)
public PatternHelper( ItemStack is, World w )
{
NBTTagCompound encodedValue = is.getTagCompound();
if ( encodedValue == null )
if( encodedValue == null )
throw new RuntimeException( "No pattern here!" );
NBTTagList inTag = encodedValue.getTagList( "in", 10 );
@@ -159,12 +76,12 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
List<IAEItemStack> in = new ArrayList<IAEItemStack>();
List<IAEItemStack> out = new ArrayList<IAEItemStack>();
for (int x = 0; x < inTag.tagCount(); x++)
for( int x = 0; x < inTag.tagCount(); x++ )
{
ItemStack gs = ItemStack.loadItemStackFromNBT( inTag.getCompoundTagAt( x ) );
this.crafting.setInventorySlotContents( x, gs );
if ( gs != null && (!this.isCrafting || !gs.hasTagCompound()) )
if( gs != null && ( !this.isCrafting || !gs.hasTagCompound() ) )
{
this.markItemAs( x, gs, TestStatus.ACCEPT );
}
@@ -173,10 +90,10 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
this.testFrame.setInventorySlotContents( x, gs );
}
if ( this.isCrafting )
if( this.isCrafting )
{
this.standardRecipe = Platform.findMatchingRecipe( this.crafting, w );
if ( this.standardRecipe != null )
if( this.standardRecipe != null )
{
this.correctOutput = this.standardRecipe.getCraftingResult( this.crafting );
out.add( AEApi.instance().storage().createItemStack( this.correctOutput ) );
@@ -189,10 +106,10 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
this.standardRecipe = null;
this.correctOutput = null;
for (int x = 0; x < outTag.tagCount(); x++)
for( int x = 0; x < outTag.tagCount(); x++ )
{
ItemStack gs = ItemStack.loadItemStackFromNBT( outTag.getCompoundTagAt( x ) );
if ( gs != null )
if( gs != null )
out.add( AEApi.instance().storage().createItemStack( gs ) );
}
}
@@ -201,37 +118,37 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
this.inputs = in.toArray( new IAEItemStack[in.size()] );
HashMap<IAEItemStack, IAEItemStack> tmpOutputs = new HashMap<IAEItemStack, IAEItemStack>();
for (IAEItemStack io : this.outputs)
for( IAEItemStack io : this.outputs )
{
if ( io == null )
if( io == null )
continue;
IAEItemStack g = tmpOutputs.get( io );
if ( g == null )
if( g == null )
tmpOutputs.put( io, io.copy() );
else
g.add( io );
}
HashMap<IAEItemStack, IAEItemStack> tmpInputs = new HashMap<IAEItemStack, IAEItemStack>();
for (IAEItemStack io : this.inputs)
for( IAEItemStack io : this.inputs )
{
if ( io == null )
if( io == null )
continue;
IAEItemStack g = tmpInputs.get( io );
if ( g == null )
if( g == null )
tmpInputs.put( io, io.copy() );
else
g.add( io );
}
if ( tmpOutputs.isEmpty() || tmpInputs.isEmpty() )
if( tmpOutputs.isEmpty() || tmpInputs.isEmpty() )
throw new RuntimeException( "No pattern here!" );
int offset = 0;
this.condensedInputs = new IAEItemStack[tmpInputs.size()];
for (IAEItemStack io : tmpInputs.values())
for( IAEItemStack io : tmpInputs.values() )
{
this.condensedInputs[offset] = io;
offset++;
@@ -239,44 +156,58 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
offset = 0;
this.condensedOutputs = new IAEItemStack[tmpOutputs.size()];
for (IAEItemStack io : tmpOutputs.values())
for( IAEItemStack io : tmpOutputs.values() )
{
this.condensedOutputs[offset] = io;
offset++;
}
}
@Override
synchronized public boolean isValidItemForSlot(int slotIndex, ItemStack i, World w)
private void markItemAs( int slotIndex, ItemStack i, TestStatus b )
{
if ( !this.isCrafting )
if( b == TestStatus.TEST || i.hasTagCompound() )
return;
( b == TestStatus.ACCEPT ? this.passCache : this.failCache ).add( new TestLookup( slotIndex, i ) );
}
@Override
public ItemStack getPattern()
{
return this.patternItem;
}
@Override
synchronized public boolean isValidItemForSlot( int slotIndex, ItemStack i, World w )
{
if( !this.isCrafting )
{
throw new RuntimeException( "Only crafting recipes supported." );
}
TestStatus result = this.getStatus( slotIndex, i );
switch (result)
switch( result )
{
case ACCEPT:
return true;
case DECLINE:
return false;
case TEST:
default:
break;
case ACCEPT:
return true;
case DECLINE:
return false;
case TEST:
default:
break;
}
for (int x = 0; x < this.crafting.getSizeInventory(); x++)
for( int x = 0; x < this.crafting.getSizeInventory(); x++ )
this.testFrame.setInventorySlotContents( x, this.crafting.getStackInSlot( x ) );
this.testFrame.setInventorySlotContents( slotIndex, i );
if ( this.standardRecipe.matches( this.testFrame, w ) )
if( this.standardRecipe.matches( this.testFrame, w ) )
{
ItemStack testOutput = this.standardRecipe.getCraftingResult( this.testFrame );
if ( Platform.isSameItemPrecise( this.correctOutput, testOutput ) )
if( Platform.isSameItemPrecise( this.correctOutput, testOutput ) )
{
this.testFrame.setInventorySlotContents( slotIndex, this.crafting.getStackInSlot( slotIndex ) );
this.markItemAs( slotIndex, i, TestStatus.ACCEPT );
@@ -287,7 +218,7 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
{
ItemStack testOutput = CraftingManager.getInstance().findMatchingRecipe( this.testFrame, w );
if ( Platform.isSameItemPrecise( this.correctOutput, testOutput ) )
if( Platform.isSameItemPrecise( this.correctOutput, testOutput ) )
{
this.testFrame.setInventorySlotContents( slotIndex, this.crafting.getStackInSlot( slotIndex ) );
this.markItemAs( slotIndex, i, TestStatus.ACCEPT );
@@ -299,30 +230,6 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
return false;
}
@Override
public ItemStack getOutput(InventoryCrafting craftingInv, World w)
{
if ( !this.isCrafting )
throw new RuntimeException( "Only crafting recipes supported." );
for (int x = 0; x < craftingInv.getSizeInventory(); x++)
{
if ( !this.isValidItemForSlot( x, craftingInv.getStackInSlot( x ), w ) )
return null;
}
if ( this.outputs != null && this.outputs.length > 0 )
return this.outputs[0].getItemStack();
return null;
}
@Override
public boolean canSubstitute()
{
return false;
}
@Override
public boolean isCraftable()
{
@@ -335,18 +242,6 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
return this.inputs;
}
@Override
public IAEItemStack[] getOutputs()
{
return this.outputs;
}
@Override
public ItemStack getPattern()
{
return this.patternItem;
}
@Override
public IAEItemStack[] getCondensedInputs()
{
@@ -360,7 +255,69 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
}
@Override
public int compareTo(PatternHelper o)
public IAEItemStack[] getOutputs()
{
return this.outputs;
}
@Override
public boolean canSubstitute()
{
return false;
}
@Override
public ItemStack getOutput( InventoryCrafting craftingInv, World w )
{
if( !this.isCrafting )
throw new RuntimeException( "Only crafting recipes supported." );
for( int x = 0; x < craftingInv.getSizeInventory(); x++ )
{
if( !this.isValidItemForSlot( x, craftingInv.getStackInSlot( x ), w ) )
return null;
}
if( this.outputs != null && this.outputs.length > 0 )
return this.outputs[0].getItemStack();
return null;
}
private TestStatus getStatus( int slotIndex, ItemStack i )
{
if( this.crafting.getStackInSlot( slotIndex ) == null )
return i == null ? TestStatus.ACCEPT : TestStatus.DECLINE;
if( i == null )
return TestStatus.DECLINE;
if( i.hasTagCompound() )
return TestStatus.TEST;
if( this.passCache.contains( new TestLookup( slotIndex, i ) ) )
return TestStatus.ACCEPT;
if( this.failCache.contains( new TestLookup( slotIndex, i ) ) )
return TestStatus.DECLINE;
return TestStatus.TEST;
}
@Override
public int getPriority()
{
return this.priority;
}
@Override
public void setPriority( int priority )
{
this.priority = priority;
}
@Override
public int compareTo( PatternHelper o )
{
return ItemSorters.compareInt( o.priority, this.priority );
}
@@ -371,28 +328,67 @@ public class PatternHelper implements ICraftingPatternDetails, Comparable<Patter
return this.pattern.hashCode();
}
@Override
public boolean equals(Object obj)
enum TestStatus
{
if ( obj == null )
ACCEPT, DECLINE, TEST
}
static class TestLookup
{
final int slot;
final int ref;
final int hash;
public TestLookup( int slot, ItemStack i )
{
this( slot, i.getItem(), i.getItemDamage() );
}
public TestLookup( int slot, Item item, int dmg )
{
this.slot = slot;
this.ref = ( dmg << Platform.DEF_OFFSET ) | ( Item.getIdFromItem( item ) & 0xffff );
int offset = 3 * slot;
this.hash = ( this.ref << offset ) | ( this.ref >> ( offset + 32 ) );
}
@Override
public int hashCode()
{
return this.hash;
}
@Override
public boolean equals( Object obj )
{
final boolean equality;
if( obj instanceof TestLookup )
{
TestLookup b = (TestLookup) obj;
equality = b.slot == this.slot && b.ref == this.ref;
}
else
{
equality = false;
}
return equality;
}
}
@Override
public boolean equals( Object obj )
{
if( obj == null )
return false;
if ( this.getClass() != obj.getClass() )
if( this.getClass() != obj.getClass() )
return false;
PatternHelper other = (PatternHelper) obj;
if ( this.pattern != null && other.pattern != null )
if( this.pattern != null && other.pattern != null )
return this.pattern.equals( other.pattern );
return false;
}
@Override
public void setPriority(int priority)
{
this.priority = priority;
}
@Override
public int getPriority()
{
return this.priority;
}
}
@@ -18,23 +18,26 @@
package appeng.helpers;
import java.util.EnumSet;
import java.util.HashMap;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.security.ISecurityRegistry;
public class PlayerSecurityWrapper implements ISecurityRegistry
{
final HashMap<Integer, EnumSet<SecurityPermissions>> target;
public PlayerSecurityWrapper(HashMap<Integer, EnumSet<SecurityPermissions>> playerPerms) {
public PlayerSecurityWrapper( HashMap<Integer, EnumSet<SecurityPermissions>> playerPerms )
{
this.target = playerPerms;
}
@Override
public void addPlayer(int PlayerID, EnumSet<SecurityPermissions> permissions)
public void addPlayer( int PlayerID, EnumSet<SecurityPermissions> permissions )
{
this.target.put( PlayerID, permissions );
}
+23 -19
View File
@@ -18,6 +18,7 @@
package appeng.helpers;
import io.netty.buffer.ByteBuf;
import net.minecraft.util.Vec3;
@@ -25,23 +26,30 @@ import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.util.AEColor;
public class Splotch
{
public Splotch(AEColor col, boolean lit, ForgeDirection side, Vec3 Pos) {
final public ForgeDirection side;
final public boolean lumen;
final public AEColor color;
final private int pos;
public Splotch( AEColor col, boolean lit, ForgeDirection side, Vec3 Pos )
{
this.color = col;
this.lumen = lit;
double x;
double y;
if ( side == ForgeDirection.SOUTH || side == ForgeDirection.NORTH )
if( side == ForgeDirection.SOUTH || side == ForgeDirection.NORTH )
{
x = Pos.xCoord;
y = Pos.yCoord;
}
else if ( side == ForgeDirection.UP || side == ForgeDirection.DOWN )
else if( side == ForgeDirection.UP || side == ForgeDirection.DOWN )
{
x = Pos.xCoord;
y = Pos.zCoord;
@@ -53,48 +61,44 @@ public class Splotch
y = Pos.zCoord;
}
int a = (int) (x * 0xF);
int b = (int) (y * 0xF);
this.pos = a | (b << 4);
int a = (int) ( x * 0xF );
int b = (int) ( y * 0xF );
this.pos = a | ( b << 4 );
this.side = side;
}
public Splotch(ByteBuf data) {
public Splotch( ByteBuf data )
{
this.pos = data.readByte();
int val = data.readByte();
this.side = ForgeDirection.getOrientation( val & 0x07 );
this.color = AEColor.values()[(val >> 3) & 0x0F];
this.lumen = ((val >> 7) & 0x01) > 0;
this.color = AEColor.values()[( val >> 3 ) & 0x0F];
this.lumen = ( ( val >> 7 ) & 0x01 ) > 0;
}
public void writeToStream(ByteBuf stream)
public void writeToStream( ByteBuf stream )
{
stream.writeByte( this.pos );
int val = this.side.ordinal() | (this.color.ordinal() << 3) | (this.lumen ? 0x80 : 0x00);
int val = this.side.ordinal() | ( this.color.ordinal() << 3 ) | ( this.lumen ? 0x80 : 0x00 );
stream.writeByte( val );
}
final private int pos;
final public ForgeDirection side;
final public boolean lumen;
final public AEColor color;
public float x()
{
return (this.pos & 0x0f) / 15.0f;
return ( this.pos & 0x0f ) / 15.0f;
}
public float y()
{
return ((this.pos >> 4) & 0x0f) / 15.0f;
return ( ( this.pos >> 4 ) & 0x0f ) / 15.0f;
}
public int getSeed()
{
int val = this.side.ordinal() | (this.color.ordinal() << 3) | (this.lumen ? 0x80 : 0x00);
int val = this.side.ordinal() | ( this.color.ordinal() << 3 ) | ( this.lumen ? 0x80 : 0x00 );
return Math.abs( this.pos + val );
}
}
@@ -18,6 +18,7 @@
package appeng.helpers;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
@@ -49,29 +50,23 @@ import appeng.api.util.DimensionalCoord;
import appeng.api.util.IConfigManager;
import appeng.tile.networking.TileWireless;
public class WirelessTerminalGuiObject implements IPortableCell, IActionHost
{
public final ItemStack effectiveItem;
final IWirelessTermHandler wth;
final String encryptionKey;
final EntityPlayer myPlayer;
IGrid targetGrid;
IStorageGrid sg;
IMEMonitor<IAEItemStack> itemStorage;
IWirelessAccessPoint myWap;
double sqRange = Double.MAX_VALUE;
double myRange = Double.MAX_VALUE;
final EntityPlayer myPlayer;
public final ItemStack effectiveItem;
public double getRange()
public WirelessTerminalGuiObject( IWirelessTermHandler wh, ItemStack is, EntityPlayer ep, World w, int x, int y, int z )
{
return this.myRange;
}
public WirelessTerminalGuiObject(IWirelessTermHandler wh, ItemStack is, EntityPlayer ep, World w, int x, int y, int z) {
this.encryptionKey = wh.getEncryptionKey( is );
this.effectiveItem = is;
this.myPlayer = ep;
@@ -84,90 +79,36 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost
long encKey = Long.parseLong( this.encryptionKey );
obj = AEApi.instance().registries().locatable().getLocatableBy( encKey );
}
catch (NumberFormatException err)
catch( NumberFormatException err )
{
// :P
}
if ( obj instanceof IGridHost )
if( obj instanceof IGridHost )
{
IGridNode n = ((IGridHost) obj).getGridNode( ForgeDirection.UNKNOWN );
if ( n != null )
IGridNode n = ( (IGridHost) obj ).getGridNode( ForgeDirection.UNKNOWN );
if( n != null )
{
this.targetGrid = n.getGrid();
if ( this.targetGrid != null )
if( this.targetGrid != null )
{
this.sg = this.targetGrid.getCache( IStorageGrid.class );
if ( this.sg != null )
if( this.sg != null )
this.itemStorage = this.sg.getItemInventory();
}
}
}
}
public boolean rangeCheck()
public double getRange()
{
this.sqRange = this.myRange = Double.MAX_VALUE;
if ( this.targetGrid != null && this.itemStorage != null )
{
if ( this.myWap != null )
{
if ( this.myWap.getGrid() == this.targetGrid )
{
if ( this.testWap( this.myWap ) )
return true;
}
return false;
}
IMachineSet tw = this.targetGrid.getMachines( TileWireless.class );
this.myWap = null;
for (IGridNode n : tw)
{
IWirelessAccessPoint wap = (IWirelessAccessPoint) n.getMachine();
if ( this.testWap( wap ) )
this.myWap = wap;
}
return this.myWap != null;
}
return false;
}
private boolean testWap(IWirelessAccessPoint wap)
{
double rangeLimit = wap.getRange();
rangeLimit *= rangeLimit;
DimensionalCoord dc = wap.getLocation();
if ( dc.getWorld() == this.myPlayer.worldObj )
{
double offX = dc.x - this.myPlayer.posX;
double offY = dc.y - this.myPlayer.posY;
double offZ = dc.z - this.myPlayer.posZ;
double r = offX * offX + offY * offY + offZ * offZ;
if ( r < rangeLimit && this.sqRange > r )
{
if ( wap.isActive() )
{
this.sqRange = r;
this.myRange = Math.sqrt( r );
return true;
}
}
}
return false;
return this.myRange;
}
@Override
public IMEMonitor<IAEItemStack> getItemInventory()
{
if ( this.sg == null )
if( this.sg == null )
return null;
return this.sg.getItemInventory();
}
@@ -175,29 +116,29 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost
@Override
public IMEMonitor<IAEFluidStack> getFluidInventory()
{
if ( this.sg == null )
if( this.sg == null )
return null;
return this.sg.getFluidInventory();
}
@Override
public void addListener(IMEMonitorHandlerReceiver<IAEItemStack> l, Object verificationToken)
public void addListener( IMEMonitorHandlerReceiver<IAEItemStack> l, Object verificationToken )
{
if ( this.itemStorage != null )
if( this.itemStorage != null )
this.itemStorage.addListener( l, verificationToken );
}
@Override
public void removeListener(IMEMonitorHandlerReceiver<IAEItemStack> l)
public void removeListener( IMEMonitorHandlerReceiver<IAEItemStack> l )
{
if ( this.itemStorage != null )
if( this.itemStorage != null )
this.itemStorage.removeListener( l );
}
@Override
public IItemList<IAEItemStack> getAvailableItems(IItemList out)
public IItemList<IAEItemStack> getAvailableItems( IItemList out )
{
if ( this.itemStorage != null )
if( this.itemStorage != null )
return this.itemStorage.getAvailableItems( out );
return out;
}
@@ -205,7 +146,7 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost
@Override
public IItemList<IAEItemStack> getStorageList()
{
if ( this.itemStorage != null )
if( this.itemStorage != null )
return this.itemStorage.getStorageList();
return null;
}
@@ -213,23 +154,23 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost
@Override
public AccessRestriction getAccess()
{
if ( this.itemStorage != null )
if( this.itemStorage != null )
return this.itemStorage.getAccess();
return AccessRestriction.NO_ACCESS;
}
@Override
public boolean isPrioritized(IAEItemStack input)
public boolean isPrioritized( IAEItemStack input )
{
if ( this.itemStorage != null )
if( this.itemStorage != null )
return this.itemStorage.isPrioritized( input );
return false;
}
@Override
public boolean canAccept(IAEItemStack input)
public boolean canAccept( IAEItemStack input )
{
if ( this.itemStorage != null )
if( this.itemStorage != null )
return this.itemStorage.canAccept( input );
return false;
}
@@ -237,7 +178,7 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost
@Override
public int getPriority()
{
if ( this.itemStorage != null )
if( this.itemStorage != null )
return this.itemStorage.getPriority();
return 0;
}
@@ -245,23 +186,29 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost
@Override
public int getSlot()
{
if ( this.itemStorage != null )
if( this.itemStorage != null )
return this.itemStorage.getSlot();
return 0;
}
@Override
public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src)
public boolean validForPass( int i )
{
if ( this.itemStorage != null )
return this.itemStorage.validForPass( i );
}
@Override
public IAEItemStack injectItems( IAEItemStack input, Actionable type, BaseActionSource src )
{
if( this.itemStorage != null )
return this.itemStorage.injectItems( input, type, src );
return input;
}
@Override
public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src)
public IAEItemStack extractItems( IAEItemStack request, Actionable mode, BaseActionSource src )
{
if ( this.itemStorage != null )
if( this.itemStorage != null )
return this.itemStorage.extractItems( request, mode, src );
return null;
}
@@ -269,17 +216,17 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost
@Override
public StorageChannel getChannel()
{
if ( this.itemStorage != null )
if( this.itemStorage != null )
return this.itemStorage.getChannel();
return StorageChannel.ITEMS;
}
@Override
public double extractAEPower(double amt, Actionable mode, PowerMultiplier usePowerMultiplier)
public double extractAEPower( double amt, Actionable mode, PowerMultiplier usePowerMultiplier )
{
if ( this.wth != null && this.effectiveItem != null )
if( this.wth != null && this.effectiveItem != null )
{
if ( mode == Actionable.SIMULATE )
if( mode == Actionable.SIMULATE )
{
return this.wth.hasPower( this.myPlayer, amt, this.effectiveItem ) ? amt : 0;
}
@@ -301,13 +248,13 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost
}
@Override
public IGridNode getGridNode(ForgeDirection dir)
public IGridNode getGridNode( ForgeDirection dir )
{
return this.getActionableNode();
}
@Override
public AECableType getCableConnectionType(ForgeDirection dir)
public AECableType getCableConnectionType( ForgeDirection dir )
{
return AECableType.NONE;
}
@@ -322,15 +269,67 @@ public class WirelessTerminalGuiObject implements IPortableCell, IActionHost
public IGridNode getActionableNode()
{
this.rangeCheck();
if ( this.myWap != null )
if( this.myWap != null )
return this.myWap.getActionableNode();
return null;
}
@Override
public boolean validForPass(int i)
public boolean rangeCheck()
{
return this.itemStorage.validForPass( i );
this.sqRange = this.myRange = Double.MAX_VALUE;
if( this.targetGrid != null && this.itemStorage != null )
{
if( this.myWap != null )
{
if( this.myWap.getGrid() == this.targetGrid )
{
if( this.testWap( this.myWap ) )
return true;
}
return false;
}
IMachineSet tw = this.targetGrid.getMachines( TileWireless.class );
this.myWap = null;
for( IGridNode n : tw )
{
IWirelessAccessPoint wap = (IWirelessAccessPoint) n.getMachine();
if( this.testWap( wap ) )
this.myWap = wap;
}
return this.myWap != null;
}
return false;
}
private boolean testWap( IWirelessAccessPoint wap )
{
double rangeLimit = wap.getRange();
rangeLimit *= rangeLimit;
DimensionalCoord dc = wap.getLocation();
if( dc.getWorld() == this.myPlayer.worldObj )
{
double offX = dc.x - this.myPlayer.posX;
double offY = dc.y - this.myPlayer.posY;
double offZ = dc.z - this.myPlayer.posZ;
double r = offX * offX + offY * offY + offZ * offZ;
if( r < rangeLimit && this.sqRange > r )
{
if( wap.isActive() )
{
this.sqRange = r;
this.myRange = Math.sqrt( r );
return true;
}
}
}
return false;
}
}