reformatted all src files (#141)
This commit is contained in:
@@ -3,39 +3,28 @@ package appeng.util;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
|
||||
public class BlockPosUtils
|
||||
{
|
||||
public static long getDistance( BlockPos blockPos, BlockPos blockPos2 )
|
||||
{
|
||||
public class BlockPosUtils {
|
||||
public static long getDistance(BlockPos blockPos, BlockPos blockPos2) {
|
||||
int x;
|
||||
if( (blockPos.getX() > 0 && blockPos2.getX() > 0) || (blockPos.getX() < 0 && blockPos2.getX() < 0))
|
||||
{
|
||||
if ((blockPos.getX() > 0 && blockPos2.getX() > 0) || (blockPos.getX() < 0 && blockPos2.getX() < 0)) {
|
||||
x = blockPos.getX() - blockPos2.getX();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
x = blockPos.getX() + blockPos2.getX();
|
||||
}
|
||||
|
||||
int y;
|
||||
if( (blockPos.getY() > 0 && blockPos2.getY() > 0) || (blockPos.getY() < 0 && blockPos2.getY() < 0) )
|
||||
{
|
||||
if ((blockPos.getY() > 0 && blockPos2.getY() > 0) || (blockPos.getY() < 0 && blockPos2.getY() < 0)) {
|
||||
y = blockPos.getY() - blockPos2.getY();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
y = blockPos.getY() + blockPos2.getY();
|
||||
}
|
||||
|
||||
int z;
|
||||
if( (blockPos.getZ() > 0 && blockPos2.getZ() > 0) || (blockPos.getZ() < 0 && blockPos2.getZ() < 0) )
|
||||
{
|
||||
if ((blockPos.getZ() > 0 && blockPos2.getZ() > 0) || (blockPos.getZ() < 0 && blockPos2.getZ() < 0)) {
|
||||
z = blockPos.getZ() - blockPos2.getZ();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
z = blockPos.getZ() + blockPos2.getZ();
|
||||
}
|
||||
return Math.abs( x ) + Math.abs( y ) + Math.abs( z );
|
||||
return Math.abs(x) + Math.abs(y) + Math.abs(z);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,23 +23,19 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
||||
public class BlockUpdate implements IWorldCallable<Boolean>
|
||||
{
|
||||
private final BlockPos pos;
|
||||
public class BlockUpdate implements IWorldCallable<Boolean> {
|
||||
private final BlockPos pos;
|
||||
|
||||
BlockUpdate( final BlockPos pos )
|
||||
{
|
||||
this.pos = pos;
|
||||
}
|
||||
BlockUpdate(final BlockPos pos) {
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean call( final World world ) throws Exception
|
||||
{
|
||||
if( world.isBlockLoaded( this.pos ) )
|
||||
{
|
||||
world.notifyNeighborsOfStateChange( this.pos, Platform.AIR_BLOCK, true );
|
||||
}
|
||||
@Override
|
||||
public Boolean call(final World world) throws Exception {
|
||||
if (world.isBlockLoaded(this.pos)) {
|
||||
world.notifyNeighborsOfStateChange(this.pos, Platform.AIR_BLOCK, true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,103 +19,78 @@
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import appeng.core.AELog;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Optional;
|
||||
|
||||
import appeng.core.AELog;
|
||||
|
||||
public class ClassInstantiation<T> {
|
||||
private final Class<? extends T> template;
|
||||
private final Object[] args;
|
||||
|
||||
public class ClassInstantiation<T>
|
||||
{
|
||||
private final Class<? extends T> template;
|
||||
private final Object[] args;
|
||||
public ClassInstantiation(final Class<? extends T> template, final Object... args) {
|
||||
this.template = template;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public ClassInstantiation( final Class<? extends T> template, final Object... args )
|
||||
{
|
||||
this.template = template;
|
||||
this.args = args;
|
||||
}
|
||||
public Optional<T> get() {
|
||||
@SuppressWarnings("unchecked") final Constructor<T>[] constructors = (Constructor<T>[]) this.template.getConstructors();
|
||||
|
||||
public Optional<T> get()
|
||||
{
|
||||
@SuppressWarnings( "unchecked" )
|
||||
final Constructor<T>[] constructors = (Constructor<T>[]) this.template.getConstructors();
|
||||
for (final Constructor<T> constructor : constructors) {
|
||||
final Class<?>[] paramTypes = constructor.getParameterTypes();
|
||||
if (paramTypes.length == this.args.length) {
|
||||
boolean valid = true;
|
||||
|
||||
for( final Constructor<T> constructor : constructors )
|
||||
{
|
||||
final Class<?>[] paramTypes = constructor.getParameterTypes();
|
||||
if( paramTypes.length == this.args.length )
|
||||
{
|
||||
boolean valid = true;
|
||||
for (int idx = 0; idx < paramTypes.length; idx++) {
|
||||
final Class<?> cz = this.args[idx].getClass();
|
||||
if (!this.isClassMatch(paramTypes[idx], cz, this.args[idx])) {
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
|
||||
for( int idx = 0; idx < paramTypes.length; idx++ )
|
||||
{
|
||||
final Class<?> cz = this.args[idx].getClass();
|
||||
if( !this.isClassMatch( paramTypes[idx], cz, this.args[idx] ) )
|
||||
{
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
if (valid) {
|
||||
try {
|
||||
return Optional.of(constructor.newInstance(this.args));
|
||||
} catch (final InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (final IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (final InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( valid )
|
||||
{
|
||||
try
|
||||
{
|
||||
return Optional.of( constructor.newInstance( this.args ) );
|
||||
}
|
||||
catch( final InstantiationException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch( final IllegalAccessException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch( final InvocationTargetException e )
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
private boolean isClassMatch(Class<?> expected, Class<?> got, final Object value) {
|
||||
if (value == null && !expected.isPrimitive()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isClassMatch( Class<?> expected, Class<?> got, final Object value )
|
||||
{
|
||||
if( value == null && !expected.isPrimitive() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
expected = this.condense(expected, Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class);
|
||||
got = this.condense(got, Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class);
|
||||
|
||||
expected = this.condense( expected, Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class );
|
||||
got = this.condense( got, Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class );
|
||||
return expected == got || expected.isAssignableFrom(got);
|
||||
}
|
||||
|
||||
return expected == got || expected.isAssignableFrom( got );
|
||||
}
|
||||
|
||||
private Class<?> condense( final Class<?> expected, final Class<?>... wrappers )
|
||||
{
|
||||
if( expected.isPrimitive() )
|
||||
{
|
||||
for( final Class clz : wrappers )
|
||||
{
|
||||
try
|
||||
{
|
||||
if( expected == clz.getField( "TYPE" ).get( null ) )
|
||||
{
|
||||
return clz;
|
||||
}
|
||||
}
|
||||
catch( final Throwable t )
|
||||
{
|
||||
AELog.debug( t );
|
||||
}
|
||||
}
|
||||
}
|
||||
return expected;
|
||||
}
|
||||
private Class<?> condense(final Class<?> expected, final Class<?>... wrappers) {
|
||||
if (expected.isPrimitive()) {
|
||||
for (final Class clz : wrappers) {
|
||||
try {
|
||||
if (expected == clz.getField("TYPE").get(null)) {
|
||||
return clz;
|
||||
}
|
||||
} catch (final Throwable t) {
|
||||
AELog.debug(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
return expected;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,120 +19,101 @@
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import appeng.api.config.LevelEmitterMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.StorageFilter;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.core.AELog;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public final class ConfigManager implements IConfigManager
|
||||
{
|
||||
private final Map<Settings, Enum<?>> settings = new EnumMap<>( Settings.class );
|
||||
private final IConfigManagerHost target;
|
||||
private Map<Settings, Enum<?>> oldSettings = new EnumMap<>( Settings.class );
|
||||
public final class ConfigManager implements IConfigManager {
|
||||
private final Map<Settings, Enum<?>> settings = new EnumMap<>(Settings.class);
|
||||
private final IConfigManagerHost target;
|
||||
private final Map<Settings, Enum<?>> oldSettings = new EnumMap<>(Settings.class);
|
||||
|
||||
public ConfigManager( final IConfigManagerHost tile )
|
||||
{
|
||||
this.target = tile;
|
||||
}
|
||||
public ConfigManager(final IConfigManagerHost tile) {
|
||||
this.target = tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Settings> getSettings()
|
||||
{
|
||||
return this.settings.keySet();
|
||||
}
|
||||
@Override
|
||||
public Set<Settings> getSettings() {
|
||||
return this.settings.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerSetting( final Settings settingName, final Enum defaultValue )
|
||||
{
|
||||
this.settings.put( settingName, defaultValue );
|
||||
}
|
||||
@Override
|
||||
public void registerSetting(final Settings settingName, final Enum defaultValue) {
|
||||
this.settings.put(settingName, defaultValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum<?> getSetting( final Settings settingName )
|
||||
{
|
||||
final Enum<?> oldValue = this.settings.get( settingName );
|
||||
@Override
|
||||
public Enum<?> getSetting(final Settings settingName) {
|
||||
final Enum<?> oldValue = this.settings.get(settingName);
|
||||
|
||||
if( oldValue != null )
|
||||
{
|
||||
return oldValue;
|
||||
}
|
||||
if (oldValue != null) {
|
||||
return oldValue;
|
||||
}
|
||||
|
||||
throw new IllegalStateException( "Invalid Config setting. Expected a non-null value for " + settingName );
|
||||
}
|
||||
throw new IllegalStateException("Invalid Config setting. Expected a non-null value for " + settingName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Enum<?> putSetting( final Settings settingName, final Enum newValue )
|
||||
{
|
||||
final Enum<?> oldValue = this.getSetting( settingName );
|
||||
this.settings.put( settingName, newValue );
|
||||
this.oldSettings.put( settingName, oldValue );
|
||||
this.target.updateSetting( this, settingName, newValue );
|
||||
return oldValue;
|
||||
}
|
||||
@Override
|
||||
public Enum<?> putSetting(final Settings settingName, final Enum newValue) {
|
||||
final Enum<?> oldValue = this.getSetting(settingName);
|
||||
this.settings.put(settingName, newValue);
|
||||
this.oldSettings.put(settingName, oldValue);
|
||||
this.target.updateSetting(this, settingName, newValue);
|
||||
return oldValue;
|
||||
}
|
||||
|
||||
public Enum<?> getOldSetting(final Settings settingName){
|
||||
return this.oldSettings.get( settingName );
|
||||
}
|
||||
public Enum<?> getOldSetting(final Settings settingName) {
|
||||
return this.oldSettings.get(settingName);
|
||||
}
|
||||
|
||||
/**
|
||||
* save all settings using config manager.
|
||||
*
|
||||
* @param tagCompound to be written to compound
|
||||
*/
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound tagCompound )
|
||||
{
|
||||
for( final Map.Entry<Settings, Enum<?>> entry : this.settings.entrySet() )
|
||||
{
|
||||
tagCompound.setString( entry.getKey().name(), this.settings.get( entry.getKey() ).toString() );
|
||||
}
|
||||
}
|
||||
/**
|
||||
* save all settings using config manager.
|
||||
*
|
||||
* @param tagCompound to be written to compound
|
||||
*/
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound tagCompound) {
|
||||
for (final Map.Entry<Settings, Enum<?>> entry : this.settings.entrySet()) {
|
||||
tagCompound.setString(entry.getKey().name(), this.settings.get(entry.getKey()).toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* read all settings using config manager.
|
||||
*
|
||||
* @param tagCompound to be read from compound
|
||||
*/
|
||||
@Override
|
||||
public void readFromNBT( final NBTTagCompound tagCompound )
|
||||
{
|
||||
for( final Map.Entry<Settings, Enum<?>> entry : this.settings.entrySet() )
|
||||
{
|
||||
try
|
||||
{
|
||||
if( tagCompound.hasKey( entry.getKey().name() ) )
|
||||
{
|
||||
String value = tagCompound.getString( entry.getKey().name() );
|
||||
/**
|
||||
* read all settings using config manager.
|
||||
*
|
||||
* @param tagCompound to be read from compound
|
||||
*/
|
||||
@Override
|
||||
public void readFromNBT(final NBTTagCompound tagCompound) {
|
||||
for (final Map.Entry<Settings, Enum<?>> entry : this.settings.entrySet()) {
|
||||
try {
|
||||
if (tagCompound.hasKey(entry.getKey().name())) {
|
||||
String value = tagCompound.getString(entry.getKey().name());
|
||||
|
||||
// Provides an upgrade path for the rename of this value in the API between rv1 and rv2
|
||||
if( value.equals( "EXTACTABLE_ONLY" ) )
|
||||
{
|
||||
value = StorageFilter.EXTRACTABLE_ONLY.toString();
|
||||
}
|
||||
else if( value.equals( "STOREABLE_AMOUNT" ) )
|
||||
{
|
||||
value = LevelEmitterMode.STORABLE_AMOUNT.toString();
|
||||
}
|
||||
// Provides an upgrade path for the rename of this value in the API between rv1 and rv2
|
||||
if (value.equals("EXTACTABLE_ONLY")) {
|
||||
value = StorageFilter.EXTRACTABLE_ONLY.toString();
|
||||
} else if (value.equals("STOREABLE_AMOUNT")) {
|
||||
value = LevelEmitterMode.STORABLE_AMOUNT.toString();
|
||||
}
|
||||
|
||||
final Enum<?> oldValue = this.settings.get( entry.getKey() );
|
||||
final Enum<?> oldValue = this.settings.get(entry.getKey());
|
||||
|
||||
final Enum<?> newValue = Enum.valueOf( oldValue.getClass(), value );
|
||||
final Enum<?> newValue = Enum.valueOf(oldValue.getClass(), value);
|
||||
|
||||
this.putSetting( entry.getKey(), newValue );
|
||||
}
|
||||
}
|
||||
catch( final IllegalArgumentException e )
|
||||
{
|
||||
AELog.debug( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
this.putSetting(entry.getKey(), newValue);
|
||||
}
|
||||
} catch (final IllegalArgumentException e) {
|
||||
AELog.debug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,7 @@ package appeng.util;
|
||||
import appeng.api.util.IConfigManager;
|
||||
|
||||
|
||||
public interface IConfigManagerHost
|
||||
{
|
||||
public interface IConfigManagerHost {
|
||||
|
||||
void updateSetting( IConfigManager manager, Enum settingName, Enum newValue );
|
||||
void updateSetting(IConfigManager manager, Enum settingName, Enum newValue);
|
||||
}
|
||||
|
||||
@@ -30,20 +30,18 @@ import javax.annotation.Nonnegative;
|
||||
* @version rv2
|
||||
* @since rv2
|
||||
*/
|
||||
public interface ISlimReadableNumberConverter
|
||||
{
|
||||
/**
|
||||
* Converts a number into a human readable form. It will not round the number, but down it.
|
||||
* Will try to cut the number down 1 decimal later, but rarely because of the 3 width limitation.
|
||||
* Can only handle non negative numbers
|
||||
*
|
||||
* Example:
|
||||
* 10000L -> 10K
|
||||
* 9999L -> 9K, not 9.9K cause 4 width
|
||||
*
|
||||
* @param number to be converted number
|
||||
*
|
||||
* @return String in SI format cut down as far as possible
|
||||
*/
|
||||
String toSlimReadableForm( @Nonnegative long number );
|
||||
public interface ISlimReadableNumberConverter {
|
||||
/**
|
||||
* Converts a number into a human readable form. It will not round the number, but down it.
|
||||
* Will try to cut the number down 1 decimal later, but rarely because of the 3 width limitation.
|
||||
* Can only handle non negative numbers
|
||||
* <p>
|
||||
* Example:
|
||||
* 10000L -> 10K
|
||||
* 9999L -> 9K, not 9.9K cause 4 width
|
||||
*
|
||||
* @param number to be converted number
|
||||
* @return String in SI format cut down as far as possible
|
||||
*/
|
||||
String toSlimReadableForm(@Nonnegative long number);
|
||||
}
|
||||
|
||||
@@ -29,20 +29,18 @@ import javax.annotation.Nonnegative;
|
||||
* @version rv2
|
||||
* @since rv2
|
||||
*/
|
||||
public interface IWideReadableNumberConverter
|
||||
{
|
||||
/**
|
||||
* Converts a number into a human readable form. It will not round the number, but down it.
|
||||
* Will try to cut the number down 1 decimal later if width can be below 4.
|
||||
* Can only handle non negative numbers
|
||||
*
|
||||
* Example:
|
||||
* 10000L -> 10K
|
||||
* 9999L -> 9999
|
||||
*
|
||||
* @param number to be converted number
|
||||
*
|
||||
* @return String in SI format cut down as far as possible
|
||||
*/
|
||||
String toWideReadableForm( @Nonnegative long number );
|
||||
public interface IWideReadableNumberConverter {
|
||||
/**
|
||||
* Converts a number into a human readable form. It will not round the number, but down it.
|
||||
* Will try to cut the number down 1 decimal later if width can be below 4.
|
||||
* Can only handle non negative numbers
|
||||
* <p>
|
||||
* Example:
|
||||
* 10000L -> 10K
|
||||
* 9999L -> 9999
|
||||
*
|
||||
* @param number to be converted number
|
||||
* @return String in SI format cut down as far as possible
|
||||
*/
|
||||
String toWideReadableForm(@Nonnegative long number);
|
||||
}
|
||||
|
||||
@@ -19,11 +19,10 @@
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
|
||||
/**
|
||||
@@ -34,19 +33,16 @@ import net.minecraft.world.World;
|
||||
* @see Callable
|
||||
* @since rv3
|
||||
*/
|
||||
public interface IWorldCallable<T>
|
||||
{
|
||||
/**
|
||||
* Similar to {@link Callable#call()}
|
||||
*
|
||||
* @param world this param is given to not hold a reference to the world but let the caller handle it. Do not expect
|
||||
* a world here thus can be <tt>null</tt>.
|
||||
*
|
||||
* @return result of call on the world. Can be <tt>null</tt>.
|
||||
*
|
||||
* @throws Exception if the call fails
|
||||
* @see Callable#call()
|
||||
*/
|
||||
@Nullable
|
||||
T call( @Nullable World world ) throws Exception;
|
||||
public interface IWorldCallable<T> {
|
||||
/**
|
||||
* Similar to {@link Callable#call()}
|
||||
*
|
||||
* @param world this param is given to not hold a reference to the world but let the caller handle it. Do not expect
|
||||
* a world here thus can be <tt>null</tt>.
|
||||
* @return result of call on the world. Can be <tt>null</tt>.
|
||||
* @throws Exception if the call fails
|
||||
* @see Callable#call()
|
||||
*/
|
||||
@Nullable
|
||||
T call(@Nullable World world) throws Exception;
|
||||
}
|
||||
|
||||
@@ -19,70 +19,60 @@
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockAir;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class InWorldToolOperationResult
|
||||
{
|
||||
|
||||
private final IBlockState blockState;
|
||||
private final List<ItemStack> drops;
|
||||
public class InWorldToolOperationResult {
|
||||
|
||||
public InWorldToolOperationResult()
|
||||
{
|
||||
this.blockState = null;
|
||||
this.drops = null;
|
||||
}
|
||||
private final IBlockState blockState;
|
||||
private final List<ItemStack> drops;
|
||||
|
||||
public InWorldToolOperationResult( final IBlockState block, final List<ItemStack> drops )
|
||||
{
|
||||
this.blockState = block;
|
||||
this.drops = drops;
|
||||
}
|
||||
public InWorldToolOperationResult() {
|
||||
this.blockState = null;
|
||||
this.drops = null;
|
||||
}
|
||||
|
||||
public InWorldToolOperationResult( final IBlockState block )
|
||||
{
|
||||
this.blockState = block;
|
||||
this.drops = null;
|
||||
}
|
||||
public InWorldToolOperationResult(final IBlockState block, final List<ItemStack> drops) {
|
||||
this.blockState = block;
|
||||
this.drops = drops;
|
||||
}
|
||||
|
||||
public static InWorldToolOperationResult getBlockOperationResult( final ItemStack[] items )
|
||||
{
|
||||
final List<ItemStack> temp = new ArrayList<>();
|
||||
IBlockState b = null;
|
||||
public InWorldToolOperationResult(final IBlockState block) {
|
||||
this.blockState = block;
|
||||
this.drops = null;
|
||||
}
|
||||
|
||||
for( final ItemStack l : items )
|
||||
{
|
||||
if( b == null )
|
||||
{
|
||||
final Block bl = Block.getBlockFromItem( l.getItem() );
|
||||
public static InWorldToolOperationResult getBlockOperationResult(final ItemStack[] items) {
|
||||
final List<ItemStack> temp = new ArrayList<>();
|
||||
IBlockState b = null;
|
||||
|
||||
if( bl != null && !( bl instanceof BlockAir ) )
|
||||
{
|
||||
b = bl.getDefaultState();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (final ItemStack l : items) {
|
||||
if (b == null) {
|
||||
final Block bl = Block.getBlockFromItem(l.getItem());
|
||||
|
||||
temp.add( l );
|
||||
}
|
||||
if (bl != null && !(bl instanceof BlockAir)) {
|
||||
b = bl.getDefaultState();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return new InWorldToolOperationResult( b, temp );
|
||||
}
|
||||
temp.add(l);
|
||||
}
|
||||
|
||||
public IBlockState getBlockState()
|
||||
{
|
||||
return this.blockState;
|
||||
}
|
||||
return new InWorldToolOperationResult(b, temp);
|
||||
}
|
||||
|
||||
public List<ItemStack> getDrops()
|
||||
{
|
||||
return this.drops;
|
||||
}
|
||||
public IBlockState getBlockState() {
|
||||
return this.blockState;
|
||||
}
|
||||
|
||||
public List<ItemStack> getDrops() {
|
||||
return this.drops;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.inv.*;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.capabilities.IItemRepository;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -30,70 +31,59 @@ import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
|
||||
/**
|
||||
* Universal Facade for other inventories. Used to conveniently interact with various types of inventories. This is not
|
||||
* used for
|
||||
* actually monitoring an inventory. It is just for insertion and extraction, and is primarily used by import/export
|
||||
* buses.
|
||||
*/
|
||||
public abstract class InventoryAdaptor implements Iterable<ItemSlot>
|
||||
{
|
||||
@CapabilityInject( IItemRepository.class)
|
||||
public static Capability<IItemRepository> ITEM_REPOSITORY_CAPABILITY = null;
|
||||
public abstract class InventoryAdaptor implements Iterable<ItemSlot> {
|
||||
@CapabilityInject(IItemRepository.class)
|
||||
public static Capability<IItemRepository> ITEM_REPOSITORY_CAPABILITY = null;
|
||||
|
||||
public static InventoryAdaptor getAdaptor( final TileEntity te, final EnumFacing d )
|
||||
{
|
||||
if( te != null )
|
||||
{
|
||||
if( ITEM_REPOSITORY_CAPABILITY != null && te.hasCapability( ITEM_REPOSITORY_CAPABILITY, d ) )
|
||||
{
|
||||
IItemRepository itemRepository = te.getCapability( ITEM_REPOSITORY_CAPABILITY, d );
|
||||
if (itemRepository != null){
|
||||
return new AdaptorItemRepository( itemRepository );
|
||||
}
|
||||
}
|
||||
else if( te.hasCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d ) )
|
||||
{
|
||||
public static InventoryAdaptor getAdaptor(final TileEntity te, final EnumFacing d) {
|
||||
if (te != null) {
|
||||
if (ITEM_REPOSITORY_CAPABILITY != null && te.hasCapability(ITEM_REPOSITORY_CAPABILITY, d)) {
|
||||
IItemRepository itemRepository = te.getCapability(ITEM_REPOSITORY_CAPABILITY, d);
|
||||
if (itemRepository != null) {
|
||||
return new AdaptorItemRepository(itemRepository);
|
||||
}
|
||||
} else if (te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d)) {
|
||||
|
||||
// Attempt getting an IItemHandler for the given side via caps
|
||||
IItemHandler itemHandler = te.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d );
|
||||
if( itemHandler != null )
|
||||
{
|
||||
return new AdaptorItemHandler( itemHandler );
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// Attempt getting an IItemHandler for the given side via caps
|
||||
IItemHandler itemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d);
|
||||
if (itemHandler != null) {
|
||||
return new AdaptorItemHandler(itemHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static InventoryAdaptor getAdaptor( final EntityPlayer te )
|
||||
{
|
||||
if( te != null )
|
||||
{
|
||||
return new AdaptorItemHandlerPlayerInv( te );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static InventoryAdaptor getAdaptor(final EntityPlayer te) {
|
||||
if (te != null) {
|
||||
return new AdaptorItemHandlerPlayerInv(te);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// return what was extracted.
|
||||
public abstract ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination );
|
||||
// return what was extracted.
|
||||
public abstract ItemStack removeItems(int amount, ItemStack filter, IInventoryDestination destination);
|
||||
|
||||
public abstract ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination );
|
||||
public abstract ItemStack simulateRemove(int amount, ItemStack filter, IInventoryDestination destination);
|
||||
|
||||
// return what was extracted.
|
||||
public abstract ItemStack removeSimilarItems( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination );
|
||||
// return what was extracted.
|
||||
public abstract ItemStack removeSimilarItems(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination);
|
||||
|
||||
public abstract ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination );
|
||||
public abstract ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination);
|
||||
|
||||
// return what isn't used...
|
||||
public abstract ItemStack addItems( ItemStack toBeAdded );
|
||||
// return what isn't used...
|
||||
public abstract ItemStack addItems(ItemStack toBeAdded);
|
||||
|
||||
public abstract ItemStack simulateAdd( ItemStack toBeSimulated );
|
||||
public abstract ItemStack simulateAdd(ItemStack toBeSimulated);
|
||||
|
||||
public abstract boolean containsItems();
|
||||
public abstract boolean containsItems();
|
||||
|
||||
public abstract boolean hasSlots();
|
||||
public abstract boolean hasSlots();
|
||||
|
||||
}
|
||||
|
||||
@@ -19,105 +19,90 @@
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import appeng.api.config.SortDir;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.integration.Integrations;
|
||||
import appeng.integration.abstraction.IInvTweaks;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class ItemSorters
|
||||
{
|
||||
|
||||
private static SortDir Direction = SortDir.ASCENDING;
|
||||
public class ItemSorters {
|
||||
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_NAME = ( o1, o2 ) ->
|
||||
{
|
||||
final int cmp = Platform.getItemDisplayName( o1 ).compareToIgnoreCase( Platform.getItemDisplayName( o2 ) );
|
||||
return applyDirection( cmp );
|
||||
};
|
||||
private static SortDir Direction = SortDir.ASCENDING;
|
||||
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_MOD = ( o1, o2 ) ->
|
||||
{
|
||||
final AEItemStack op1 = (AEItemStack) o1;
|
||||
final AEItemStack op2 = (AEItemStack) o2;
|
||||
int cmp = op1.getModID().compareToIgnoreCase( op2.getModID() );
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_NAME = (o1, o2) ->
|
||||
{
|
||||
final int cmp = Platform.getItemDisplayName(o1).compareToIgnoreCase(Platform.getItemDisplayName(o2));
|
||||
return applyDirection(cmp);
|
||||
};
|
||||
|
||||
if( cmp == 0 )
|
||||
{
|
||||
cmp = Platform.getItemDisplayName( o1 ).compareToIgnoreCase( Platform.getItemDisplayName( o2 ) );
|
||||
}
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_MOD = (o1, o2) ->
|
||||
{
|
||||
final AEItemStack op1 = (AEItemStack) o1;
|
||||
final AEItemStack op2 = (AEItemStack) o2;
|
||||
int cmp = op1.getModID().compareToIgnoreCase(op2.getModID());
|
||||
|
||||
return applyDirection( cmp );
|
||||
};
|
||||
if (cmp == 0) {
|
||||
cmp = Platform.getItemDisplayName(o1).compareToIgnoreCase(Platform.getItemDisplayName(o2));
|
||||
}
|
||||
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_SIZE = ( o1, o2 ) ->
|
||||
{
|
||||
final int cmp = Long.compare( o2.getStackSize(), o1.getStackSize() );
|
||||
return applyDirection( cmp );
|
||||
};
|
||||
return applyDirection(cmp);
|
||||
};
|
||||
|
||||
private static IInvTweaks api;
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_SIZE = (o1, o2) ->
|
||||
{
|
||||
final int cmp = Long.compare(o2.getStackSize(), o1.getStackSize());
|
||||
return applyDirection(cmp);
|
||||
};
|
||||
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_INV_TWEAKS = ( o1, o2 ) ->
|
||||
{
|
||||
if( api == null )
|
||||
{
|
||||
return CONFIG_BASED_SORT_BY_NAME.compare( o1, o2 );
|
||||
}
|
||||
private static IInvTweaks api;
|
||||
|
||||
final int cmp = api.compareItems( o1.createItemStack(), o2.createItemStack() );
|
||||
return applyDirection( cmp );
|
||||
};
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_INV_TWEAKS = (o1, o2) ->
|
||||
{
|
||||
if (api == null) {
|
||||
return CONFIG_BASED_SORT_BY_NAME.compare(o1, o2);
|
||||
}
|
||||
|
||||
public static void init()
|
||||
{
|
||||
if( api != null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
final int cmp = api.compareItems(o1.createItemStack(), o2.createItemStack());
|
||||
return applyDirection(cmp);
|
||||
};
|
||||
|
||||
if( Integrations.invTweaks().isEnabled() )
|
||||
{
|
||||
api = Integrations.invTweaks();
|
||||
}
|
||||
else
|
||||
{
|
||||
api = null;
|
||||
}
|
||||
}
|
||||
public static void init() {
|
||||
if (api != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
public static int compareLong( final long a, final long b )
|
||||
{
|
||||
if( a == b )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if( a < b )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (Integrations.invTweaks().isEnabled()) {
|
||||
api = Integrations.invTweaks();
|
||||
} else {
|
||||
api = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static SortDir getDirection()
|
||||
{
|
||||
return Direction;
|
||||
}
|
||||
public static int compareLong(final long a, final long b) {
|
||||
if (a == b) {
|
||||
return 0;
|
||||
}
|
||||
if (a < b) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static void setDirection( final SortDir direction )
|
||||
{
|
||||
Direction = direction;
|
||||
}
|
||||
private static SortDir getDirection() {
|
||||
return Direction;
|
||||
}
|
||||
|
||||
private static int applyDirection( int cmp )
|
||||
{
|
||||
if( getDirection() == SortDir.ASCENDING )
|
||||
{
|
||||
return cmp;
|
||||
}
|
||||
return -cmp;
|
||||
}
|
||||
public static void setDirection(final SortDir direction) {
|
||||
Direction = direction;
|
||||
}
|
||||
|
||||
private static int applyDirection(int cmp) {
|
||||
if (getDirection() == SortDir.ASCENDING) {
|
||||
return cmp;
|
||||
}
|
||||
return -cmp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,23 +22,19 @@ package appeng.util;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
public class Lazy<T> implements Supplier<T>
|
||||
{
|
||||
private final Supplier<T> supplier;
|
||||
private T instance = null;
|
||||
public class Lazy<T> implements Supplier<T> {
|
||||
private final Supplier<T> supplier;
|
||||
private T instance = null;
|
||||
|
||||
public Lazy( final Supplier<T> supplier )
|
||||
{
|
||||
this.supplier = supplier;
|
||||
}
|
||||
public Lazy(final Supplier<T> supplier) {
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get()
|
||||
{
|
||||
if( this.instance == null )
|
||||
{
|
||||
this.instance = this.supplier.get();
|
||||
}
|
||||
return this.instance;
|
||||
}
|
||||
@Override
|
||||
public T get() {
|
||||
if (this.instance == null) {
|
||||
this.instance = this.supplier.get();
|
||||
}
|
||||
return this.instance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,25 +22,21 @@ package appeng.util;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
|
||||
public class LookDirection
|
||||
{
|
||||
public class LookDirection {
|
||||
|
||||
private final Vec3d a;
|
||||
private final Vec3d b;
|
||||
private final Vec3d a;
|
||||
private final Vec3d b;
|
||||
|
||||
public LookDirection( final Vec3d a, final Vec3d b )
|
||||
{
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
public LookDirection(final Vec3d a, final Vec3d b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public Vec3d getA()
|
||||
{
|
||||
return this.a;
|
||||
}
|
||||
public Vec3d getA() {
|
||||
return this.a;
|
||||
}
|
||||
|
||||
public Vec3d getB()
|
||||
{
|
||||
return this.b;
|
||||
}
|
||||
public Vec3d getB() {
|
||||
return this.b;
|
||||
}
|
||||
}
|
||||
|
||||
+1369
-1656
File diff suppressed because it is too large
Load Diff
@@ -19,43 +19,37 @@
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import appeng.api.util.IReadOnlyCollection;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.api.util.IReadOnlyCollection;
|
||||
|
||||
public class ReadOnlyCollection<T> implements IReadOnlyCollection<T> {
|
||||
|
||||
public class ReadOnlyCollection<T> implements IReadOnlyCollection<T>
|
||||
{
|
||||
private final Collection<T> c;
|
||||
|
||||
private final Collection<T> c;
|
||||
public ReadOnlyCollection(final Collection<T> in) {
|
||||
this.c = in;
|
||||
}
|
||||
|
||||
public ReadOnlyCollection( final Collection<T> in )
|
||||
{
|
||||
this.c = in;
|
||||
}
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return this.c.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator()
|
||||
{
|
||||
return this.c.iterator();
|
||||
}
|
||||
@Override
|
||||
public int size() {
|
||||
return this.c.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return this.c.size();
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.c.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return this.c.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains( final Object node )
|
||||
{
|
||||
return this.c.contains( (T) node );
|
||||
}
|
||||
@Override
|
||||
public boolean contains(final Object node) {
|
||||
return this.c.contains((T) node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,93 +32,85 @@ import java.text.Format;
|
||||
* @version rv2
|
||||
* @since rv2
|
||||
*/
|
||||
public enum ReadableNumberConverter implements ISlimReadableNumberConverter, IWideReadableNumberConverter
|
||||
{
|
||||
INSTANCE;
|
||||
public enum ReadableNumberConverter implements ISlimReadableNumberConverter, IWideReadableNumberConverter {
|
||||
INSTANCE;
|
||||
|
||||
/**
|
||||
* Defines the base for a division, non-si standard could be 1024 for kilobytes
|
||||
*/
|
||||
private static final int DIVISION_BASE = 1000;
|
||||
/**
|
||||
* Defines the base for a division, non-si standard could be 1024 for kilobytes
|
||||
*/
|
||||
private static final int DIVISION_BASE = 1000;
|
||||
|
||||
/**
|
||||
* String representation of the sorted postfixes
|
||||
*/
|
||||
private static final char[] ENCODED_POSTFIXES = "KMGTPE".toCharArray();
|
||||
/**
|
||||
* String representation of the sorted postfixes
|
||||
*/
|
||||
private static final char[] ENCODED_POSTFIXES = "KMGTPE".toCharArray();
|
||||
|
||||
private final Format format;
|
||||
private final Format format;
|
||||
|
||||
/**
|
||||
* Initializes the specific decimal format with special format for negative and positive numbers
|
||||
*/
|
||||
ReadableNumberConverter()
|
||||
{
|
||||
final DecimalFormatSymbols symbols = new DecimalFormatSymbols();
|
||||
symbols.setDecimalSeparator( '.' );
|
||||
final DecimalFormat format = new DecimalFormat( ".#;0.#" );
|
||||
format.setDecimalFormatSymbols( symbols );
|
||||
format.setRoundingMode( RoundingMode.DOWN );
|
||||
/**
|
||||
* Initializes the specific decimal format with special format for negative and positive numbers
|
||||
*/
|
||||
ReadableNumberConverter() {
|
||||
final DecimalFormatSymbols symbols = new DecimalFormatSymbols();
|
||||
symbols.setDecimalSeparator('.');
|
||||
final DecimalFormat format = new DecimalFormat(".#;0.#");
|
||||
format.setDecimalFormatSymbols(symbols);
|
||||
format.setRoundingMode(RoundingMode.DOWN);
|
||||
|
||||
this.format = format;
|
||||
}
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSlimReadableForm( final long number )
|
||||
{
|
||||
return this.toReadableFormRestrictedByWidth( number, 3 );
|
||||
}
|
||||
@Override
|
||||
public String toSlimReadableForm(final long number) {
|
||||
return this.toReadableFormRestrictedByWidth(number, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* restricts a string representation of a number to a specific width
|
||||
*
|
||||
* @param number to be formatted number
|
||||
* @param width width limitation of the resulting number
|
||||
*
|
||||
* @return formatted number restricted by the width limitation
|
||||
*/
|
||||
private String toReadableFormRestrictedByWidth( final long number, final int width )
|
||||
{
|
||||
assert number >= 0;
|
||||
/**
|
||||
* restricts a string representation of a number to a specific width
|
||||
*
|
||||
* @param number to be formatted number
|
||||
* @param width width limitation of the resulting number
|
||||
* @return formatted number restricted by the width limitation
|
||||
*/
|
||||
private String toReadableFormRestrictedByWidth(final long number, final int width) {
|
||||
assert number >= 0;
|
||||
|
||||
// handles low numbers more efficiently since no format is needed
|
||||
final String numberString = Long.toString( number );
|
||||
int numberSize = numberString.length();
|
||||
if( numberSize <= width )
|
||||
{
|
||||
return numberString;
|
||||
}
|
||||
// handles low numbers more efficiently since no format is needed
|
||||
final String numberString = Long.toString(number);
|
||||
int numberSize = numberString.length();
|
||||
if (numberSize <= width) {
|
||||
return numberString;
|
||||
}
|
||||
|
||||
long base = number;
|
||||
double last = base * 1000;
|
||||
int exponent = -1;
|
||||
String postFix = "";
|
||||
long base = number;
|
||||
double last = base * 1000;
|
||||
int exponent = -1;
|
||||
String postFix = "";
|
||||
|
||||
while( numberSize > width )
|
||||
{
|
||||
last = base;
|
||||
base /= DIVISION_BASE;
|
||||
while (numberSize > width) {
|
||||
last = base;
|
||||
base /= DIVISION_BASE;
|
||||
|
||||
exponent++;
|
||||
exponent++;
|
||||
|
||||
// adds +1 due to the postfix
|
||||
numberSize = Long.toString( base ).length() + 1;
|
||||
postFix = String.valueOf( ENCODED_POSTFIXES[exponent] );
|
||||
}
|
||||
// adds +1 due to the postfix
|
||||
numberSize = Long.toString(base).length() + 1;
|
||||
postFix = String.valueOf(ENCODED_POSTFIXES[exponent]);
|
||||
}
|
||||
|
||||
final String withPrecision = this.format.format( last / DIVISION_BASE ) + postFix;
|
||||
final String withoutPrecision = Long.toString( base ) + postFix;
|
||||
final String withPrecision = this.format.format(last / DIVISION_BASE) + postFix;
|
||||
final String withoutPrecision = base + postFix;
|
||||
|
||||
final String slimResult = ( withPrecision.length() <= width ) ? withPrecision : withoutPrecision;
|
||||
final String slimResult = (withPrecision.length() <= width) ? withPrecision : withoutPrecision;
|
||||
|
||||
// post condition
|
||||
assert slimResult.length() <= width;
|
||||
// post condition
|
||||
assert slimResult.length() <= width;
|
||||
|
||||
return slimResult;
|
||||
}
|
||||
return slimResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toWideReadableForm( final long number )
|
||||
{
|
||||
return this.toReadableFormRestrictedByWidth( number, 4 );
|
||||
}
|
||||
@Override
|
||||
public String toWideReadableForm(final long number) {
|
||||
return this.toReadableFormRestrictedByWidth(number, 4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,10 @@
|
||||
package appeng.util;
|
||||
|
||||
|
||||
public enum SettingsFrom
|
||||
{
|
||||
// moved the item, and replaced it.
|
||||
DISMANTLE_ITEM,
|
||||
public enum SettingsFrom {
|
||||
// moved the item, and replaced it.
|
||||
DISMANTLE_ITEM,
|
||||
|
||||
// used memory card?
|
||||
MEMORY_CARD
|
||||
// used memory card?
|
||||
MEMORY_CARD
|
||||
}
|
||||
|
||||
@@ -25,27 +25,24 @@ import java.util.regex.Pattern;
|
||||
/**
|
||||
* Regex wrapper for {@link java.util.UUID}s to not rely on try catch
|
||||
*/
|
||||
public final class UUIDMatcher
|
||||
{
|
||||
/**
|
||||
* String which is the regular expression for {@link java.util.UUID}s
|
||||
*/
|
||||
private static final String UUID_REGEX = "[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}";
|
||||
public final class UUIDMatcher {
|
||||
/**
|
||||
* String which is the regular expression for {@link java.util.UUID}s
|
||||
*/
|
||||
private static final String UUID_REGEX = "[0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}";
|
||||
|
||||
/**
|
||||
* Pattern which pre-compiles the {@link appeng.util.UUIDMatcher#UUID_REGEX}
|
||||
*/
|
||||
private static final Pattern PATTERN = Pattern.compile( UUID_REGEX );
|
||||
/**
|
||||
* Pattern which pre-compiles the {@link appeng.util.UUIDMatcher#UUID_REGEX}
|
||||
*/
|
||||
private static final Pattern PATTERN = Pattern.compile(UUID_REGEX);
|
||||
|
||||
/**
|
||||
* Checks if a potential {@link java.util.UUID} is an {@link java.util.UUID} by applying a regular expression on it.
|
||||
*
|
||||
* @param potential to be checked potential {@link java.util.UUID}
|
||||
*
|
||||
* @return true, if the potential {@link java.util.UUID} is indeed an {@link java.util.UUID}
|
||||
*/
|
||||
public boolean isUUID( final CharSequence potential )
|
||||
{
|
||||
return PATTERN.matcher( potential ).matches();
|
||||
}
|
||||
/**
|
||||
* Checks if a potential {@link java.util.UUID} is an {@link java.util.UUID} by applying a regular expression on it.
|
||||
*
|
||||
* @param potential to be checked potential {@link java.util.UUID}
|
||||
* @return true, if the potential {@link java.util.UUID} is indeed an {@link java.util.UUID}
|
||||
*/
|
||||
public boolean isUUID(final CharSequence potential) {
|
||||
return PATTERN.matcher(potential).matches();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,142 +19,120 @@
|
||||
package appeng.util.helpers;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.item.OreHelper;
|
||||
import appeng.util.item.OreReference;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.item.OreHelper;
|
||||
import appeng.util.item.OreReference;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
||||
/**
|
||||
* A helper class for comparing {@link Item}, {@link ItemStack} or NBT
|
||||
*
|
||||
*/
|
||||
public class ItemComparisonHelper
|
||||
{
|
||||
public class ItemComparisonHelper {
|
||||
|
||||
/**
|
||||
* Compare the two {@link ItemStack}s based on the same {@link Item} and damage value.
|
||||
*
|
||||
* In case of the item being damageable, only the {@link Item} will be considered.
|
||||
* If not it will also compare both damage values.
|
||||
*
|
||||
* Ignores NBT.
|
||||
*
|
||||
* @return true, if both are equal.
|
||||
*/
|
||||
public boolean isEqualItemType( @Nonnull final ItemStack that, @Nonnull final ItemStack other )
|
||||
{
|
||||
if( !that.isEmpty() && !other.isEmpty() && that.getItem() == other.getItem() )
|
||||
{
|
||||
if( that.isItemStackDamageable() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return that.getItemDamage() == other.getItemDamage();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Compare the two {@link ItemStack}s based on the same {@link Item} and damage value.
|
||||
* <p>
|
||||
* In case of the item being damageable, only the {@link Item} will be considered.
|
||||
* If not it will also compare both damage values.
|
||||
* <p>
|
||||
* Ignores NBT.
|
||||
*
|
||||
* @return true, if both are equal.
|
||||
*/
|
||||
public boolean isEqualItemType(@Nonnull final ItemStack that, @Nonnull final ItemStack other) {
|
||||
if (!that.isEmpty() && !other.isEmpty() && that.getItem() == other.getItem()) {
|
||||
if (that.isItemStackDamageable()) {
|
||||
return true;
|
||||
}
|
||||
return that.getItemDamage() == other.getItemDamage();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two {@link ItemStack} and their NBT tag for equality.
|
||||
*
|
||||
* Use this when a precise check is required and the same item is required.
|
||||
* Not just something with different NBT tags.
|
||||
*
|
||||
* @return true, if both are identical.
|
||||
*/
|
||||
public boolean isSameItem( @Nonnull final ItemStack is, @Nonnull final ItemStack filter )
|
||||
{
|
||||
return ItemStack.areItemsEqual( is, filter ) && this.isNbtTagEqual( is.getTagCompound(), filter.getTagCompound() );
|
||||
}
|
||||
/**
|
||||
* Compares two {@link ItemStack} and their NBT tag for equality.
|
||||
* <p>
|
||||
* Use this when a precise check is required and the same item is required.
|
||||
* Not just something with different NBT tags.
|
||||
*
|
||||
* @return true, if both are identical.
|
||||
*/
|
||||
public boolean isSameItem(@Nonnull final ItemStack is, @Nonnull final ItemStack filter) {
|
||||
return ItemStack.areItemsEqual(is, filter) && this.isNbtTagEqual(is.getTagCompound(), filter.getTagCompound());
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to {@link ItemComparisonHelper#isEqualItem(ItemStack, ItemStack)},
|
||||
* but it can further check, if both match the same {@link FuzzyMode}
|
||||
* or are considered equal by the {@link OreDictionary}
|
||||
*
|
||||
* @param mode how to compare the two {@link ItemStack}s
|
||||
* @return true, if both are matching the mode or considered equal by the {@link OreDictionary}
|
||||
*/
|
||||
public boolean isFuzzyEqualItem( final ItemStack a, final ItemStack b, final FuzzyMode mode )
|
||||
{
|
||||
if( a.isEmpty() && b.isEmpty() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Similar to {@link ItemComparisonHelper#isEqualItem(ItemStack, ItemStack)},
|
||||
* but it can further check, if both match the same {@link FuzzyMode}
|
||||
* or are considered equal by the {@link OreDictionary}
|
||||
*
|
||||
* @param mode how to compare the two {@link ItemStack}s
|
||||
* @return true, if both are matching the mode or considered equal by the {@link OreDictionary}
|
||||
*/
|
||||
public boolean isFuzzyEqualItem(final ItemStack a, final ItemStack b, final FuzzyMode mode) {
|
||||
if (a.isEmpty() && b.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if( a.isEmpty() || b.isEmpty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (a.isEmpty() || b.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// test damageable items..
|
||||
if( a.getItem() == b.getItem() && a.getItem().isDamageable() )
|
||||
{
|
||||
if( mode == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if( mode == FuzzyMode.PERCENT_99 )
|
||||
{
|
||||
return ( a.getItemDamage() > 1 ) == ( b.getItemDamage() > 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
final float percentDamagedOfA = (float) a.getItemDamage() / (float) a.getMaxDamage();
|
||||
final float percentDamagedOfB = (float) b.getItemDamage() / (float) b.getMaxDamage();
|
||||
// test damageable items..
|
||||
if (a.getItem() == b.getItem() && a.getItem().isDamageable()) {
|
||||
if (mode == FuzzyMode.IGNORE_ALL) {
|
||||
return true;
|
||||
} else if (mode == FuzzyMode.PERCENT_99) {
|
||||
return (a.getItemDamage() > 1) == (b.getItemDamage() > 1);
|
||||
} else {
|
||||
final float percentDamagedOfA = (float) a.getItemDamage() / (float) a.getMaxDamage();
|
||||
final float percentDamagedOfB = (float) b.getItemDamage() / (float) b.getMaxDamage();
|
||||
|
||||
return ( percentDamagedOfA > mode.breakPoint ) == ( percentDamagedOfB > mode.breakPoint );
|
||||
}
|
||||
}
|
||||
return (percentDamagedOfA > mode.breakPoint) == (percentDamagedOfB > mode.breakPoint);
|
||||
}
|
||||
}
|
||||
|
||||
final OreReference aOR = OreHelper.INSTANCE.getOre( a ).orElse( null );
|
||||
final OreReference bOR = OreHelper.INSTANCE.getOre( b ).orElse( null );
|
||||
final OreReference aOR = OreHelper.INSTANCE.getOre(a).orElse(null);
|
||||
final OreReference bOR = OreHelper.INSTANCE.getOre(b).orElse(null);
|
||||
|
||||
if( OreHelper.INSTANCE.sameOre( aOR, bOR ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (OreHelper.INSTANCE.sameOre(aOR, bOR)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return a.isItemEqual( b );
|
||||
}
|
||||
return a.isItemEqual(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* recursive test for NBT Equality, this was faster then trying to compare / generate hashes, its also more reliable
|
||||
* then the vanilla version which likes to fail when NBT Compound data changes order, it is pretty expensive
|
||||
* performance wise, so try an use shared tag compounds as long as the system remains in AE.
|
||||
*/
|
||||
public boolean isNbtTagEqual( final NBTBase left, final NBTBase right )
|
||||
{
|
||||
if( left == right )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* recursive test for NBT Equality, this was faster then trying to compare / generate hashes, its also more reliable
|
||||
* then the vanilla version which likes to fail when NBT Compound data changes order, it is pretty expensive
|
||||
* performance wise, so try an use shared tag compounds as long as the system remains in AE.
|
||||
*/
|
||||
public boolean isNbtTagEqual(final NBTBase left, final NBTBase right) {
|
||||
if (left == right) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final boolean isLeftEmpty = left == null || left.hasNoTags();
|
||||
final boolean isRightEmpty = right == null || right.hasNoTags();
|
||||
final boolean isLeftEmpty = left == null || left.hasNoTags();
|
||||
final boolean isRightEmpty = right == null || right.hasNoTags();
|
||||
|
||||
if( isLeftEmpty && isRightEmpty )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (isLeftEmpty && isRightEmpty) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if( isLeftEmpty != isRightEmpty )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (isLeftEmpty != isRightEmpty) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( left != null )
|
||||
{
|
||||
return left.equals( right );
|
||||
}
|
||||
if (left != null) {
|
||||
return left.equals(right);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,58 +25,43 @@ import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
|
||||
public class ItemHandlerUtil
|
||||
{
|
||||
private ItemHandlerUtil()
|
||||
{
|
||||
}
|
||||
public class ItemHandlerUtil {
|
||||
private ItemHandlerUtil() {
|
||||
}
|
||||
|
||||
public static void setStackInSlot( final IItemHandler inv, final int slot, final ItemStack stack )
|
||||
{
|
||||
if( inv instanceof IItemHandlerModifiable )
|
||||
{
|
||||
( (IItemHandlerModifiable) inv ).setStackInSlot( slot, stack );
|
||||
}
|
||||
else
|
||||
{
|
||||
inv.extractItem( slot, Integer.MAX_VALUE, false );
|
||||
inv.insertItem( slot, stack, false );
|
||||
}
|
||||
}
|
||||
public static void setStackInSlot(final IItemHandler inv, final int slot, final ItemStack stack) {
|
||||
if (inv instanceof IItemHandlerModifiable) {
|
||||
((IItemHandlerModifiable) inv).setStackInSlot(slot, stack);
|
||||
} else {
|
||||
inv.extractItem(slot, Integer.MAX_VALUE, false);
|
||||
inv.insertItem(slot, stack, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void clear( final IItemHandler inv )
|
||||
{
|
||||
for( int x = 0; x < inv.getSlots(); x++ )
|
||||
{
|
||||
setStackInSlot( inv, x, ItemStack.EMPTY );
|
||||
}
|
||||
}
|
||||
public static void clear(final IItemHandler inv) {
|
||||
for (int x = 0; x < inv.getSlots(); x++) {
|
||||
setStackInSlot(inv, x, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEmpty( final IItemHandler inv )
|
||||
{
|
||||
for( int x = 0; x < inv.getSlots(); x++ )
|
||||
{
|
||||
if( !inv.getStackInSlot( x ).isEmpty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static boolean isEmpty(final IItemHandler inv) {
|
||||
for (int x = 0; x < inv.getSlots(); x++) {
|
||||
if (!inv.getStackInSlot(x).isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void copy( final IItemHandler from, final IItemHandler to, boolean deepCopy )
|
||||
{
|
||||
for( int i = 0; i < Math.min( from.getSlots(), to.getSlots() ); ++i )
|
||||
{
|
||||
setStackInSlot( to, i, deepCopy ? from.getStackInSlot( i ).copy() : from.getStackInSlot( i ) );
|
||||
}
|
||||
}
|
||||
public static void copy(final IItemHandler from, final IItemHandler to, boolean deepCopy) {
|
||||
for (int i = 0; i < Math.min(from.getSlots(), to.getSlots()); ++i) {
|
||||
setStackInSlot(to, i, deepCopy ? from.getStackInSlot(i).copy() : from.getStackInSlot(i));
|
||||
}
|
||||
}
|
||||
|
||||
public static void copy( final InventoryCrafting from, final IItemHandler to, boolean deepCopy )
|
||||
{
|
||||
for( int i = 0; i < Math.min( from.getSizeInventory(), to.getSlots() ); ++i )
|
||||
{
|
||||
setStackInSlot( to, i, deepCopy ? from.getStackInSlot( i ).copy() : from.getStackInSlot( i ) );
|
||||
}
|
||||
}
|
||||
public static void copy(final InventoryCrafting from, final IItemHandler to, boolean deepCopy) {
|
||||
for (int i = 0; i < Math.min(from.getSizeInventory(), to.getSlots()); ++i) {
|
||||
setStackInSlot(to, i, deepCopy ? from.getStackInSlot(i).copy() : from.getStackInSlot(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,52 +19,44 @@
|
||||
package appeng.util.helpers;
|
||||
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
|
||||
public class P2PHelper {
|
||||
|
||||
public class P2PHelper
|
||||
{
|
||||
public AEColor[] toColors(short frequency) {
|
||||
final AEColor[] colors = new AEColor[4];
|
||||
|
||||
public AEColor[] toColors( short frequency )
|
||||
{
|
||||
final AEColor[] colors = new AEColor[4];
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int nibble = (frequency >> 4 * (3 - i)) & 0xF;
|
||||
|
||||
for( int i = 0; i < 4; i++ )
|
||||
{
|
||||
int nibble = ( frequency >> 4 * ( 3 - i ) ) & 0xF;
|
||||
colors[i] = AEColor.values()[nibble];
|
||||
}
|
||||
|
||||
colors[i] = AEColor.values()[nibble];
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
||||
return colors;
|
||||
}
|
||||
public short fromColors(AEColor[] colors) {
|
||||
Preconditions.checkArgument(colors.length == 4);
|
||||
|
||||
public short fromColors( AEColor[] colors )
|
||||
{
|
||||
Preconditions.checkArgument( colors.length == 4 );
|
||||
int t = 0;
|
||||
|
||||
int t = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int code = colors[3 - i].ordinal() << 4 * i;
|
||||
|
||||
for( int i = 0; i < 4; i++ )
|
||||
{
|
||||
int code = colors[3 - i].ordinal() << 4 * i;
|
||||
t |= code;
|
||||
}
|
||||
|
||||
t |= code;
|
||||
}
|
||||
return (short) (t & 0xFFFF);
|
||||
}
|
||||
|
||||
return (short) ( t & 0xFFFF );
|
||||
}
|
||||
public String toHexDigit(AEColor color) {
|
||||
return String.format("%01X", color.ordinal());
|
||||
}
|
||||
|
||||
public String toHexDigit( AEColor color )
|
||||
{
|
||||
return String.format( "%01X", color.ordinal() );
|
||||
}
|
||||
|
||||
public String toHexString( short frequency )
|
||||
{
|
||||
return String.format( "%04X", frequency );
|
||||
}
|
||||
public String toHexString(short frequency) {
|
||||
return String.format("%04X", frequency);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,246 +28,201 @@ import net.minecraftforge.items.IItemHandler;
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
public class AdaptorItemHandler extends InventoryAdaptor
|
||||
{
|
||||
protected final IItemHandler itemHandler;
|
||||
public class AdaptorItemHandler extends InventoryAdaptor {
|
||||
protected final IItemHandler itemHandler;
|
||||
|
||||
public AdaptorItemHandler( IItemHandler itemHandler )
|
||||
{
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
public AdaptorItemHandler(IItemHandler itemHandler) {
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSlots()
|
||||
{
|
||||
return this.itemHandler.getSlots() > 0;
|
||||
}
|
||||
@Override
|
||||
public boolean hasSlots() {
|
||||
return this.itemHandler.getSlots() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
|
||||
{
|
||||
int slots = this.itemHandler.getSlots();
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
@Override
|
||||
public ItemStack removeItems(int amount, ItemStack filter, IInventoryDestination destination) {
|
||||
int slots = this.itemHandler.getSlots();
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
|
||||
for( int slot = 0; slot < slots && amount > 0; slot++ )
|
||||
{
|
||||
final ItemStack is = this.itemHandler.getStackInSlot( slot );
|
||||
if( is.isEmpty() || ( !filter.isEmpty() && !Platform.itemComparisons().isSameItem( is, filter ) ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (int slot = 0; slot < slots && amount > 0; slot++) {
|
||||
final ItemStack is = this.itemHandler.getStackInSlot(slot);
|
||||
if (is.isEmpty() || (!filter.isEmpty() && !Platform.itemComparisons().isSameItem(is, filter))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
if( !destination.canInsert( is ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (destination != null) {
|
||||
if (!destination.canInsert(is)) {
|
||||
break;
|
||||
}
|
||||
|
||||
ItemStack extracted = this.itemHandler.extractItem( slot, amount, true );
|
||||
if( extracted.isEmpty() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
ItemStack extracted = this.itemHandler.extractItem(slot, amount, true);
|
||||
if (extracted.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt extracting it
|
||||
ItemStack extracted = this.itemHandler.extractItem( slot, amount, false );
|
||||
// Attempt extracting it
|
||||
ItemStack extracted = this.itemHandler.extractItem(slot, amount, false);
|
||||
|
||||
if( extracted.isEmpty() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (extracted.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( rv.isEmpty() )
|
||||
{
|
||||
// Use the first stack as a template for the result
|
||||
rv = extracted;
|
||||
filter = extracted;
|
||||
amount -= extracted.getCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Subsequent stacks will just increase the extracted size
|
||||
rv.grow( extracted.getCount() );
|
||||
amount -= extracted.getCount();
|
||||
}
|
||||
}
|
||||
if (rv.isEmpty()) {
|
||||
// Use the first stack as a template for the result
|
||||
rv = extracted;
|
||||
filter = extracted;
|
||||
amount -= extracted.getCount();
|
||||
} else {
|
||||
// Subsequent stacks will just increase the extracted size
|
||||
rv.grow(extracted.getCount());
|
||||
amount -= extracted.getCount();
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination )
|
||||
{
|
||||
int slots = this.itemHandler.getSlots();
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
@Override
|
||||
public ItemStack simulateRemove(int amount, ItemStack filter, IInventoryDestination destination) {
|
||||
int slots = this.itemHandler.getSlots();
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
|
||||
for( int slot = 0; slot < slots && amount > 0; slot++ )
|
||||
{
|
||||
final ItemStack is = this.itemHandler.getStackInSlot( slot );
|
||||
if( !is.isEmpty() && ( filter.isEmpty() || Platform.itemComparisons().isSameItem( is, filter ) ) )
|
||||
{
|
||||
if( destination != null )
|
||||
{
|
||||
if( !destination.canInsert( is ) )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int slot = 0; slot < slots && amount > 0; slot++) {
|
||||
final ItemStack is = this.itemHandler.getStackInSlot(slot);
|
||||
if (!is.isEmpty() && (filter.isEmpty() || Platform.itemComparisons().isSameItem(is, filter))) {
|
||||
if (destination != null) {
|
||||
if (!destination.canInsert(is)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack extracted = this.itemHandler.extractItem( slot, amount, true );
|
||||
if( extracted.isEmpty() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
ItemStack extracted = this.itemHandler.extractItem(slot, amount, true);
|
||||
if (extracted.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( rv.isEmpty() )
|
||||
{
|
||||
// Use the first stack as a template for the result
|
||||
rv = extracted.copy();
|
||||
filter = extracted;
|
||||
amount -= extracted.getCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Subsequent stacks will just increase the extracted size
|
||||
rv.grow( extracted.getCount() );
|
||||
amount -= extracted.getCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rv.isEmpty()) {
|
||||
// Use the first stack as a template for the result
|
||||
rv = extracted.copy();
|
||||
filter = extracted;
|
||||
amount -= extracted.getCount();
|
||||
} else {
|
||||
// Subsequent stacks will just increase the extracted size
|
||||
rv.grow(extracted.getCount());
|
||||
amount -= extracted.getCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* For fuzzy extract, we will only ever extract one slot, since we're afraid of merging two item stacks with
|
||||
* different damage values.
|
||||
*/
|
||||
@Override
|
||||
public ItemStack removeSimilarItems( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
int slots = this.itemHandler.getSlots();
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
/**
|
||||
* For fuzzy extract, we will only ever extract one slot, since we're afraid of merging two item stacks with
|
||||
* different damage values.
|
||||
*/
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination) {
|
||||
int slots = this.itemHandler.getSlots();
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
|
||||
for( int slot = 0; slot < slots && extracted.isEmpty(); slot++ )
|
||||
{
|
||||
final ItemStack is = this.itemHandler.getStackInSlot( slot );
|
||||
if( is.isEmpty() || ( !filter.isEmpty() && !Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (int slot = 0; slot < slots && extracted.isEmpty(); slot++) {
|
||||
final ItemStack is = this.itemHandler.getStackInSlot(slot);
|
||||
if (is.isEmpty() || (!filter.isEmpty() && !Platform.itemComparisons().isFuzzyEqualItem(is, filter, fuzzyMode))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
if( !destination.canInsert( is ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (destination != null) {
|
||||
if (!destination.canInsert(is)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack simulated = this.itemHandler.extractItem( slot, amount, true );
|
||||
if( simulated.isEmpty() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
ItemStack simulated = this.itemHandler.extractItem(slot, amount, true);
|
||||
if (simulated.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Attempt extracting it
|
||||
extracted = this.itemHandler.extractItem( slot, amount, false );
|
||||
if( !extracted.isEmpty() )
|
||||
{
|
||||
return extracted;
|
||||
}
|
||||
}
|
||||
// Attempt extracting it
|
||||
extracted = this.itemHandler.extractItem(slot, amount, false);
|
||||
if (!extracted.isEmpty()) {
|
||||
return extracted;
|
||||
}
|
||||
}
|
||||
|
||||
return extracted;
|
||||
}
|
||||
return extracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
int slots = this.itemHandler.getSlots();
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination) {
|
||||
int slots = this.itemHandler.getSlots();
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
|
||||
for( int slot = 0; slot < slots && extracted.isEmpty(); slot++ )
|
||||
{
|
||||
final ItemStack is = this.itemHandler.getStackInSlot( slot );
|
||||
if( is.isEmpty() || ( !filter.isEmpty() && !Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (int slot = 0; slot < slots && extracted.isEmpty(); slot++) {
|
||||
final ItemStack is = this.itemHandler.getStackInSlot(slot);
|
||||
if (is.isEmpty() || (!filter.isEmpty() && !Platform.itemComparisons().isFuzzyEqualItem(is, filter, fuzzyMode))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (destination != null && !destination.canInsert(is)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Attempt extracting it
|
||||
extracted = this.itemHandler.extractItem( slot, amount, true );
|
||||
if( !extracted.isEmpty() )
|
||||
{
|
||||
return extracted;
|
||||
}
|
||||
}
|
||||
// Attempt extracting it
|
||||
extracted = this.itemHandler.extractItem(slot, amount, true);
|
||||
if (!extracted.isEmpty()) {
|
||||
return extracted;
|
||||
}
|
||||
}
|
||||
|
||||
return extracted;
|
||||
}
|
||||
return extracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems( ItemStack toBeAdded )
|
||||
{
|
||||
return this.addItems( toBeAdded, false );
|
||||
}
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack toBeAdded) {
|
||||
return this.addItems(toBeAdded, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd( ItemStack toBeSimulated )
|
||||
{
|
||||
return this.addItems( toBeSimulated, true );
|
||||
}
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack toBeSimulated) {
|
||||
return this.addItems(toBeSimulated, true);
|
||||
}
|
||||
|
||||
protected ItemStack addItems( ItemStack itemsToAdd, final boolean simulate )
|
||||
{
|
||||
if( itemsToAdd.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
protected ItemStack addItems(ItemStack itemsToAdd, final boolean simulate) {
|
||||
if (itemsToAdd.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
for( int slot = 0; slot < this.itemHandler.getSlots(); slot++ )
|
||||
{
|
||||
if( !simulate )
|
||||
{
|
||||
itemsToAdd = itemsToAdd.copy();
|
||||
}
|
||||
itemsToAdd = this.itemHandler.insertItem( slot, itemsToAdd, simulate );
|
||||
for (int slot = 0; slot < this.itemHandler.getSlots(); slot++) {
|
||||
if (!simulate) {
|
||||
itemsToAdd = itemsToAdd.copy();
|
||||
}
|
||||
itemsToAdd = this.itemHandler.insertItem(slot, itemsToAdd, simulate);
|
||||
|
||||
if( itemsToAdd.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
if (itemsToAdd.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
return itemsToAdd;
|
||||
}
|
||||
return itemsToAdd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
int slots = this.itemHandler.getSlots();
|
||||
for( int slot = 0; slot < slots; slot++ )
|
||||
{
|
||||
if( !this.itemHandler.getStackInSlot( slot ).isEmpty() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean containsItems() {
|
||||
int slots = this.itemHandler.getSlots();
|
||||
for (int slot = 0; slot < slots; slot++) {
|
||||
if (!this.itemHandler.getStackInSlot(slot).isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new ItemHandlerIterator( this.itemHandler );
|
||||
}
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator() {
|
||||
return new ItemHandlerIterator(this.itemHandler);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,57 +19,47 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.wrapper.PlayerMainInvWrapper;
|
||||
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class AdaptorItemHandlerPlayerInv extends AdaptorItemHandler {
|
||||
public AdaptorItemHandlerPlayerInv(final EntityPlayer playerInv) {
|
||||
super(new PlayerMainInvWrapper(playerInv.inventory));
|
||||
}
|
||||
|
||||
public class AdaptorItemHandlerPlayerInv extends AdaptorItemHandler
|
||||
{
|
||||
public AdaptorItemHandlerPlayerInv( final EntityPlayer playerInv )
|
||||
{
|
||||
super( new PlayerMainInvWrapper( playerInv.inventory ) );
|
||||
}
|
||||
/**
|
||||
* Tries to fill existing stacks first
|
||||
*/
|
||||
@Override
|
||||
protected ItemStack addItems(final ItemStack itemsToAdd, final boolean simulate) {
|
||||
if (itemsToAdd.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to fill existing stacks first
|
||||
*/
|
||||
@Override
|
||||
protected ItemStack addItems( final ItemStack itemsToAdd, final boolean simulate )
|
||||
{
|
||||
if( itemsToAdd.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
ItemStack left = itemsToAdd.copy();
|
||||
|
||||
ItemStack left = itemsToAdd.copy();
|
||||
for (int slot = 0; slot < this.itemHandler.getSlots(); slot++) {
|
||||
ItemStack is = this.itemHandler.getStackInSlot(slot);
|
||||
|
||||
for( int slot = 0; slot < this.itemHandler.getSlots(); slot++ )
|
||||
{
|
||||
ItemStack is = this.itemHandler.getStackInSlot( slot );
|
||||
if (Platform.itemComparisons().isSameItem(is, left)) {
|
||||
left = this.itemHandler.insertItem(slot, left, simulate);
|
||||
}
|
||||
if (left.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
if( Platform.itemComparisons().isSameItem( is, left ) )
|
||||
{
|
||||
left = this.itemHandler.insertItem( slot, left, simulate );
|
||||
}
|
||||
if( left.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
for (int slot = 0; slot < this.itemHandler.getSlots(); slot++) {
|
||||
left = this.itemHandler.insertItem(slot, left, simulate);
|
||||
if (left.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
for( int slot = 0; slot < this.itemHandler.getSlots(); slot++ )
|
||||
{
|
||||
left = this.itemHandler.insertItem( slot, left, simulate );
|
||||
if( left.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
return left;
|
||||
}
|
||||
return left;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package appeng.util.inv;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
|
||||
import appeng.util.Platform;
|
||||
import com.jaquadro.minecraft.storagedrawers.api.capabilities.IItemRepository;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -10,203 +9,164 @@ import net.minecraft.item.ItemStack;
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
public class AdaptorItemRepository extends InventoryAdaptor
|
||||
{
|
||||
protected final IItemRepository itemRepository;
|
||||
public class AdaptorItemRepository extends InventoryAdaptor {
|
||||
protected final IItemRepository itemRepository;
|
||||
|
||||
public AdaptorItemRepository( IItemRepository itemRepository )
|
||||
{
|
||||
this.itemRepository = itemRepository;
|
||||
}
|
||||
public AdaptorItemRepository(IItemRepository itemRepository) {
|
||||
this.itemRepository = itemRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
|
||||
{
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
@Override
|
||||
public ItemStack removeItems(int amount, ItemStack filter, IInventoryDestination destination) {
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
|
||||
if( !filter.isEmpty() )
|
||||
{
|
||||
extracted = this.itemRepository.extractItem( filter, amount, true );
|
||||
}
|
||||
else
|
||||
{
|
||||
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() )
|
||||
{
|
||||
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true );
|
||||
if( !extracted.isEmpty() )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!filter.isEmpty()) {
|
||||
extracted = this.itemRepository.extractItem(filter, amount, true);
|
||||
} else {
|
||||
for (IItemRepository.ItemRecord record : this.itemRepository.getAllItems()) {
|
||||
extracted = this.itemRepository.extractItem(record.itemPrototype, amount, true);
|
||||
if (!extracted.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
if (destination != null) {
|
||||
|
||||
if( extracted.isEmpty() || !destination.canInsert( extracted ) )
|
||||
{
|
||||
return rv;
|
||||
}
|
||||
if (extracted.isEmpty() || !destination.canInsert(extracted)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
extracted = this.itemRepository.extractItem( filter.isEmpty() ? extracted : filter, amount, false );
|
||||
extracted = this.itemRepository.extractItem(filter.isEmpty() ? extracted : filter, amount, false);
|
||||
|
||||
return extracted;
|
||||
}
|
||||
return extracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination )
|
||||
{
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
@Override
|
||||
public ItemStack simulateRemove(int amount, ItemStack filter, IInventoryDestination destination) {
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
|
||||
if( !filter.isEmpty() )
|
||||
{
|
||||
extracted = this.itemRepository.extractItem( filter, amount, true );
|
||||
}
|
||||
else
|
||||
{
|
||||
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() )
|
||||
{
|
||||
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true );
|
||||
if( !extracted.isEmpty() )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!filter.isEmpty()) {
|
||||
extracted = this.itemRepository.extractItem(filter, amount, true);
|
||||
} else {
|
||||
for (IItemRepository.ItemRecord record : this.itemRepository.getAllItems()) {
|
||||
extracted = this.itemRepository.extractItem(record.itemPrototype, amount, true);
|
||||
if (!extracted.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
if (destination != null) {
|
||||
|
||||
if( extracted.isEmpty() || !destination.canInsert( extracted ) )
|
||||
{
|
||||
return rv;
|
||||
}
|
||||
if (extracted.isEmpty() || !destination.canInsert(extracted)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return extracted;
|
||||
}
|
||||
return extracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination) {
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
|
||||
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() )
|
||||
{
|
||||
if( Platform.itemComparisons().isFuzzyEqualItem( record.itemPrototype, filter, fuzzyMode ) )
|
||||
{
|
||||
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true );
|
||||
}
|
||||
for (IItemRepository.ItemRecord record : this.itemRepository.getAllItems()) {
|
||||
if (Platform.itemComparisons().isFuzzyEqualItem(record.itemPrototype, filter, fuzzyMode)) {
|
||||
extracted = this.itemRepository.extractItem(record.itemPrototype, amount, true);
|
||||
}
|
||||
|
||||
if( !extracted.isEmpty() )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!extracted.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
if (destination != null) {
|
||||
|
||||
if( extracted.isEmpty() || !destination.canInsert( extracted ) )
|
||||
{
|
||||
return rv;
|
||||
}
|
||||
if (extracted.isEmpty() || !destination.canInsert(extracted)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
extracted = this.itemRepository.extractItem( extracted, amount, false );
|
||||
extracted = this.itemRepository.extractItem(extracted, amount, false);
|
||||
|
||||
return extracted;
|
||||
}
|
||||
return extracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination) {
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
|
||||
for( IItemRepository.ItemRecord record : this.itemRepository.getAllItems() )
|
||||
{
|
||||
if( Platform.itemComparisons().isFuzzyEqualItem( record.itemPrototype, filter, fuzzyMode ) )
|
||||
{
|
||||
extracted = this.itemRepository.extractItem( record.itemPrototype, amount, true );
|
||||
}
|
||||
for (IItemRepository.ItemRecord record : this.itemRepository.getAllItems()) {
|
||||
if (Platform.itemComparisons().isFuzzyEqualItem(record.itemPrototype, filter, fuzzyMode)) {
|
||||
extracted = this.itemRepository.extractItem(record.itemPrototype, amount, true);
|
||||
}
|
||||
|
||||
if( !extracted.isEmpty() )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!extracted.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
if (destination != null) {
|
||||
|
||||
if( extracted.isEmpty() || !destination.canInsert( extracted ) )
|
||||
{
|
||||
return rv;
|
||||
}
|
||||
if (extracted.isEmpty() || !destination.canInsert(extracted)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return extracted;
|
||||
}
|
||||
return extracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems( ItemStack toBeAdded )
|
||||
{
|
||||
return this.addItems( toBeAdded, false );
|
||||
}
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack toBeAdded) {
|
||||
return this.addItems(toBeAdded, false);
|
||||
}
|
||||
|
||||
protected ItemStack addItems( ItemStack itemsToAdd, final boolean simulate )
|
||||
{
|
||||
if( itemsToAdd.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
protected ItemStack addItems(ItemStack itemsToAdd, final boolean simulate) {
|
||||
if (itemsToAdd.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if( !simulate )
|
||||
{
|
||||
itemsToAdd = itemsToAdd.copy();
|
||||
}
|
||||
if (!simulate) {
|
||||
itemsToAdd = itemsToAdd.copy();
|
||||
}
|
||||
|
||||
itemsToAdd = this.itemRepository.insertItem( itemsToAdd, simulate );
|
||||
itemsToAdd = this.itemRepository.insertItem(itemsToAdd, simulate);
|
||||
|
||||
if( itemsToAdd.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
if (itemsToAdd.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return itemsToAdd;
|
||||
}
|
||||
return itemsToAdd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd( ItemStack toBeSimulated )
|
||||
{
|
||||
return this.addItems( toBeSimulated, true );
|
||||
}
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack toBeSimulated) {
|
||||
return this.addItems(toBeSimulated, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
return !this.itemRepository.getAllItems().isEmpty();
|
||||
}
|
||||
@Override
|
||||
public boolean containsItems() {
|
||||
return !this.itemRepository.getAllItems().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSlots()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean hasSlots() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,211 +19,171 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.iterators.StackToSlotIterator;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class AdaptorList extends InventoryAdaptor
|
||||
{
|
||||
public class AdaptorList extends InventoryAdaptor {
|
||||
|
||||
private final List<ItemStack> i;
|
||||
private final List<ItemStack> i;
|
||||
|
||||
public AdaptorList( final List<ItemStack> s )
|
||||
{
|
||||
this.i = s;
|
||||
}
|
||||
public AdaptorList(final List<ItemStack> s) {
|
||||
this.i = s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSlots()
|
||||
{
|
||||
return !this.i.isEmpty();
|
||||
}
|
||||
@Override
|
||||
public boolean hasSlots() {
|
||||
return !this.i.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems( int amount, final ItemStack filter, final IInventoryDestination destination )
|
||||
{
|
||||
final int s = this.i.size();
|
||||
for( int x = 0; x < s; x++ )
|
||||
{
|
||||
final ItemStack is = this.i.get( x );
|
||||
if( !is.isEmpty() && ( filter.isEmpty() || Platform.itemComparisons().isSameItem( is, filter ) ) )
|
||||
{
|
||||
if( amount > is.getCount() )
|
||||
{
|
||||
amount = is.getCount();
|
||||
}
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
{
|
||||
amount = 0;
|
||||
}
|
||||
@Override
|
||||
public ItemStack removeItems(int amount, final ItemStack filter, final IInventoryDestination destination) {
|
||||
final int s = this.i.size();
|
||||
for (int x = 0; x < s; x++) {
|
||||
final ItemStack is = this.i.get(x);
|
||||
if (!is.isEmpty() && (filter.isEmpty() || Platform.itemComparisons().isSameItem(is, filter))) {
|
||||
if (amount > is.getCount()) {
|
||||
amount = is.getCount();
|
||||
}
|
||||
if (destination != null && !destination.canInsert(is)) {
|
||||
amount = 0;
|
||||
}
|
||||
|
||||
if( amount > 0 )
|
||||
{
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount( amount );
|
||||
is.grow( -amount );
|
||||
if (amount > 0) {
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount(amount);
|
||||
is.grow(-amount);
|
||||
|
||||
// remove it..
|
||||
if( is.getCount() <= 0 )
|
||||
{
|
||||
this.i.remove( x );
|
||||
}
|
||||
// remove it..
|
||||
if (is.getCount() <= 0) {
|
||||
this.i.remove(x);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove( int amount, final ItemStack filter, final IInventoryDestination destination )
|
||||
{
|
||||
for( final ItemStack is : this.i )
|
||||
{
|
||||
if( !is.isEmpty() && ( filter.isEmpty() || Platform.itemComparisons().isSameItem( is, filter ) ) )
|
||||
{
|
||||
if( amount > is.getCount() )
|
||||
{
|
||||
amount = is.getCount();
|
||||
}
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
{
|
||||
amount = 0;
|
||||
}
|
||||
@Override
|
||||
public ItemStack simulateRemove(int amount, final ItemStack filter, final IInventoryDestination destination) {
|
||||
for (final ItemStack is : this.i) {
|
||||
if (!is.isEmpty() && (filter.isEmpty() || Platform.itemComparisons().isSameItem(is, filter))) {
|
||||
if (amount > is.getCount()) {
|
||||
amount = is.getCount();
|
||||
}
|
||||
if (destination != null && !destination.canInsert(is)) {
|
||||
amount = 0;
|
||||
}
|
||||
|
||||
if( amount > 0 )
|
||||
{
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount( amount );
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
if (amount > 0) {
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount(amount);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems( int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination )
|
||||
{
|
||||
final int s = this.i.size();
|
||||
for( int x = 0; x < s; x++ )
|
||||
{
|
||||
final ItemStack is = this.i.get( x );
|
||||
if( !is.isEmpty() && ( filter.isEmpty() || Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) )
|
||||
{
|
||||
if( amount > is.getCount() )
|
||||
{
|
||||
amount = is.getCount();
|
||||
}
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
{
|
||||
amount = 0;
|
||||
}
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination) {
|
||||
final int s = this.i.size();
|
||||
for (int x = 0; x < s; x++) {
|
||||
final ItemStack is = this.i.get(x);
|
||||
if (!is.isEmpty() && (filter.isEmpty() || Platform.itemComparisons().isFuzzyEqualItem(is, filter, fuzzyMode))) {
|
||||
if (amount > is.getCount()) {
|
||||
amount = is.getCount();
|
||||
}
|
||||
if (destination != null && !destination.canInsert(is)) {
|
||||
amount = 0;
|
||||
}
|
||||
|
||||
if( amount > 0 )
|
||||
{
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount( amount );
|
||||
is.grow( -amount );
|
||||
if (amount > 0) {
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount(amount);
|
||||
is.grow(-amount);
|
||||
|
||||
// remove it..
|
||||
if( is.getCount() <= 0 )
|
||||
{
|
||||
this.i.remove( x );
|
||||
}
|
||||
// remove it..
|
||||
if (is.getCount() <= 0) {
|
||||
this.i.remove(x);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove( int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination )
|
||||
{
|
||||
for( final ItemStack is : this.i )
|
||||
{
|
||||
if( !is.isEmpty() && ( filter.isEmpty() || Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) )
|
||||
{
|
||||
if( amount > is.getCount() )
|
||||
{
|
||||
amount = is.getCount();
|
||||
}
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
{
|
||||
amount = 0;
|
||||
}
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination) {
|
||||
for (final ItemStack is : this.i) {
|
||||
if (!is.isEmpty() && (filter.isEmpty() || Platform.itemComparisons().isFuzzyEqualItem(is, filter, fuzzyMode))) {
|
||||
if (amount > is.getCount()) {
|
||||
amount = is.getCount();
|
||||
}
|
||||
if (destination != null && !destination.canInsert(is)) {
|
||||
amount = 0;
|
||||
}
|
||||
|
||||
if( amount > 0 )
|
||||
{
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount( amount );
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
if (amount > 0) {
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount(amount);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems( final ItemStack toBeAdded )
|
||||
{
|
||||
if( toBeAdded.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
if( toBeAdded.getCount() == 0 )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public ItemStack addItems(final ItemStack toBeAdded) {
|
||||
if (toBeAdded.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
if (toBeAdded.getCount() == 0) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
final ItemStack left = toBeAdded.copy();
|
||||
final ItemStack left = toBeAdded.copy();
|
||||
|
||||
for( final ItemStack is : this.i )
|
||||
{
|
||||
if( ItemStack.areItemsEqual( is, left ) )
|
||||
{
|
||||
is.grow( left.getCount() );
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
for (final ItemStack is : this.i) {
|
||||
if (ItemStack.areItemsEqual(is, left)) {
|
||||
is.grow(left.getCount());
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
this.i.add( left );
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
this.i.add(left);
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd( final ItemStack toBeSimulated )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public ItemStack simulateAdd(final ItemStack toBeSimulated) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
for( final ItemStack is : this.i )
|
||||
{
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean containsItems() {
|
||||
for (final ItemStack is : this.i) {
|
||||
if (!is.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new StackToSlotIterator( this.i.iterator() );
|
||||
}
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator() {
|
||||
return new StackToSlotIterator(this.i.iterator());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,21 +6,17 @@ import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
|
||||
public abstract class BlockingInventoryAdaptor implements Iterable<ItemSlot>
|
||||
{
|
||||
public static BlockingInventoryAdaptor getAdaptor( final TileEntity te, final EnumFacing d )
|
||||
{
|
||||
if( te != null && te.hasCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d ) )
|
||||
{
|
||||
// Attempt getting an IItemHandler for the given side via caps
|
||||
IItemHandler itemHandler = te.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d );
|
||||
if( itemHandler != null )
|
||||
{
|
||||
return new BlockingItemHandler( itemHandler, te.getBlockType().getRegistryName().getResourceDomain() );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public abstract class BlockingInventoryAdaptor implements Iterable<ItemSlot> {
|
||||
public static BlockingInventoryAdaptor getAdaptor(final TileEntity te, final EnumFacing d) {
|
||||
if (te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d)) {
|
||||
// Attempt getting an IItemHandler for the given side via caps
|
||||
IItemHandler itemHandler = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d);
|
||||
if (itemHandler != null) {
|
||||
return new BlockingItemHandler(itemHandler, te.getBlockType().getRegistryName().getResourceDomain());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract boolean containsBlockingItems();
|
||||
public abstract boolean containsBlockingItems();
|
||||
}
|
||||
@@ -10,45 +10,37 @@ import net.minecraftforge.items.IItemHandler;
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
public class BlockingItemHandler extends BlockingInventoryAdaptor
|
||||
{
|
||||
protected final IItemHandler itemHandler;
|
||||
private final String domain;
|
||||
public class BlockingItemHandler extends BlockingInventoryAdaptor {
|
||||
protected final IItemHandler itemHandler;
|
||||
private final String domain;
|
||||
|
||||
public BlockingItemHandler( IItemHandler itemHandler, String domain )
|
||||
{
|
||||
this.itemHandler = itemHandler;
|
||||
this.domain = domain;
|
||||
}
|
||||
public BlockingItemHandler(IItemHandler itemHandler, String domain) {
|
||||
this.itemHandler = itemHandler;
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
boolean isBlockableItem( ItemStack stack )
|
||||
{
|
||||
Object2ObjectOpenHashMap<Item, IntSet> map = NonBlockingItems.INSTANCE.getMap().get( domain );
|
||||
if( map.get( stack.getItem() ) != null )
|
||||
{
|
||||
return !map.get( stack.getItem() ).contains( stack.getMetadata() );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
boolean isBlockableItem(ItemStack stack) {
|
||||
Object2ObjectOpenHashMap<Item, IntSet> map = NonBlockingItems.INSTANCE.getMap().get(domain);
|
||||
if (map.get(stack.getItem()) != null) {
|
||||
return !map.get(stack.getItem()).contains(stack.getMetadata());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsBlockingItems()
|
||||
{
|
||||
int slots = this.itemHandler.getSlots();
|
||||
for( int slot = 0; slot < slots; slot++ )
|
||||
{
|
||||
ItemStack is = this.itemHandler.getStackInSlot( slot );
|
||||
if( !is.isEmpty() && isBlockableItem( is ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean containsBlockingItems() {
|
||||
int slots = this.itemHandler.getSlots();
|
||||
for (int slot = 0; slot < slots; slot++) {
|
||||
ItemStack is = this.itemHandler.getStackInSlot(slot);
|
||||
if (!is.isEmpty() && isBlockableItem(is)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new ItemHandlerIterator( this.itemHandler );
|
||||
}
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator() {
|
||||
return new ItemHandlerIterator(this.itemHandler);
|
||||
}
|
||||
}
|
||||
@@ -23,9 +23,8 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
|
||||
public interface IAEAppEngInventory
|
||||
{
|
||||
void saveChanges();
|
||||
public interface IAEAppEngInventory {
|
||||
void saveChanges();
|
||||
|
||||
void onChangeInventory( IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack );
|
||||
void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack);
|
||||
}
|
||||
|
||||
@@ -22,8 +22,7 @@ package appeng.util.inv;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public interface IInventoryDestination
|
||||
{
|
||||
public interface IInventoryDestination {
|
||||
|
||||
boolean canInsert( ItemStack stack );
|
||||
boolean canInsert(ItemStack stack);
|
||||
}
|
||||
|
||||
@@ -19,12 +19,6 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
@@ -35,173 +29,145 @@ import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
public class IMEAdaptor extends InventoryAdaptor
|
||||
{
|
||||
public class IMEAdaptor extends InventoryAdaptor {
|
||||
|
||||
private final IMEInventory<IAEItemStack> target;
|
||||
private final IActionSource src;
|
||||
private int maxSlots = 0;
|
||||
private final IMEInventory<IAEItemStack> target;
|
||||
private final IActionSource src;
|
||||
private int maxSlots = 0;
|
||||
|
||||
public IMEAdaptor( final IMEInventory<IAEItemStack> input, final IActionSource src )
|
||||
{
|
||||
this.target = input;
|
||||
this.src = src;
|
||||
}
|
||||
public IMEAdaptor(final IMEInventory<IAEItemStack> input, final IActionSource src) {
|
||||
this.target = input;
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSlots()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean hasSlots() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new IMEAdaptorIterator( this, this.getList() );
|
||||
}
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator() {
|
||||
return new IMEAdaptorIterator(this, this.getList());
|
||||
}
|
||||
|
||||
private IItemList<IAEItemStack> getList()
|
||||
{
|
||||
return this.target.getAvailableItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() );
|
||||
}
|
||||
private IItemList<IAEItemStack> getList() {
|
||||
return this.target.getAvailableItems(AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems( final int amount, final ItemStack filter, final IInventoryDestination destination )
|
||||
{
|
||||
return this.doRemoveItems( amount, filter, destination, Actionable.MODULATE );
|
||||
}
|
||||
@Override
|
||||
public ItemStack removeItems(final int amount, final ItemStack filter, final IInventoryDestination destination) {
|
||||
return this.doRemoveItems(amount, filter, destination, Actionable.MODULATE);
|
||||
}
|
||||
|
||||
private ItemStack doRemoveItems( final int amount, final ItemStack filter, final IInventoryDestination destination, final Actionable type )
|
||||
{
|
||||
IAEItemStack req = null;
|
||||
private ItemStack doRemoveItems(final int amount, final ItemStack filter, final IInventoryDestination destination, final Actionable type) {
|
||||
IAEItemStack req = null;
|
||||
|
||||
if( filter.isEmpty() )
|
||||
{
|
||||
final IItemList<IAEItemStack> list = this.getList();
|
||||
if( !list.isEmpty() )
|
||||
{
|
||||
req = list.getFirstItem();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
req = AEItemStack.fromItemStack( filter );
|
||||
}
|
||||
if (filter.isEmpty()) {
|
||||
final IItemList<IAEItemStack> list = this.getList();
|
||||
if (!list.isEmpty()) {
|
||||
req = list.getFirstItem();
|
||||
}
|
||||
} else {
|
||||
req = AEItemStack.fromItemStack(filter);
|
||||
}
|
||||
|
||||
IAEItemStack out = null;
|
||||
IAEItemStack out = null;
|
||||
|
||||
if( req != null )
|
||||
{
|
||||
req.setStackSize( amount );
|
||||
out = this.target.extractItems( req, type, this.src );
|
||||
}
|
||||
if (req != null) {
|
||||
req.setStackSize(amount);
|
||||
out = this.target.extractItems(req, type, this.src);
|
||||
}
|
||||
|
||||
if( out != null )
|
||||
{
|
||||
return out.createItemStack();
|
||||
}
|
||||
if (out != null) {
|
||||
return out.createItemStack();
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove( final int amount, final ItemStack filter, final IInventoryDestination destination )
|
||||
{
|
||||
return this.doRemoveItems( amount, filter, destination, Actionable.SIMULATE );
|
||||
}
|
||||
@Override
|
||||
public ItemStack simulateRemove(final int amount, final ItemStack filter, final IInventoryDestination destination) {
|
||||
return this.doRemoveItems(amount, filter, destination, Actionable.SIMULATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems( final int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination )
|
||||
{
|
||||
if( filter.isEmpty() )
|
||||
{
|
||||
return this.doRemoveItems( amount, null, destination, Actionable.MODULATE );
|
||||
}
|
||||
return this.doRemoveItemsFuzzy( amount, filter, destination, Actionable.MODULATE, fuzzyMode );
|
||||
}
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(final int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination) {
|
||||
if (filter.isEmpty()) {
|
||||
return this.doRemoveItems(amount, null, destination, Actionable.MODULATE);
|
||||
}
|
||||
return this.doRemoveItemsFuzzy(amount, filter, destination, Actionable.MODULATE, fuzzyMode);
|
||||
}
|
||||
|
||||
private ItemStack doRemoveItemsFuzzy( final int amount, final ItemStack filter, final IInventoryDestination destination, final Actionable type, final FuzzyMode fuzzyMode )
|
||||
{
|
||||
final IAEItemStack reqFilter = AEItemStack.fromItemStack( filter );
|
||||
if( reqFilter == null )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
private ItemStack doRemoveItemsFuzzy(final int amount, final ItemStack filter, final IInventoryDestination destination, final Actionable type, final FuzzyMode fuzzyMode) {
|
||||
final IAEItemStack reqFilter = AEItemStack.fromItemStack(filter);
|
||||
if (reqFilter == null) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
IAEItemStack out = null;
|
||||
IAEItemStack out = null;
|
||||
|
||||
for( final IAEItemStack req : ImmutableList.copyOf( this.getList().findFuzzy( reqFilter, fuzzyMode ) ) )
|
||||
{
|
||||
if( req != null )
|
||||
{
|
||||
req.setStackSize( amount );
|
||||
out = this.target.extractItems( req, type, this.src );
|
||||
if( out != null )
|
||||
{
|
||||
return out.createItemStack();
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final IAEItemStack req : ImmutableList.copyOf(this.getList().findFuzzy(reqFilter, fuzzyMode))) {
|
||||
if (req != null) {
|
||||
req.setStackSize(amount);
|
||||
out = this.target.extractItems(req, type, this.src);
|
||||
if (out != null) {
|
||||
return out.createItemStack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove( final int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination )
|
||||
{
|
||||
if( filter.isEmpty() )
|
||||
{
|
||||
return this.doRemoveItems( amount, ItemStack.EMPTY, destination, Actionable.SIMULATE );
|
||||
}
|
||||
return this.doRemoveItemsFuzzy( amount, filter, destination, Actionable.SIMULATE, fuzzyMode );
|
||||
}
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(final int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination) {
|
||||
if (filter.isEmpty()) {
|
||||
return this.doRemoveItems(amount, ItemStack.EMPTY, destination, Actionable.SIMULATE);
|
||||
}
|
||||
return this.doRemoveItemsFuzzy(amount, filter, destination, Actionable.SIMULATE, fuzzyMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems( final ItemStack toBeAdded )
|
||||
{
|
||||
final IAEItemStack in = AEItemStack.fromItemStack( toBeAdded );
|
||||
if( in != null )
|
||||
{
|
||||
final IAEItemStack out = this.target.injectItems( in, Actionable.MODULATE, this.src );
|
||||
if( out != null )
|
||||
{
|
||||
return out.createItemStack();
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public ItemStack addItems(final ItemStack toBeAdded) {
|
||||
final IAEItemStack in = AEItemStack.fromItemStack(toBeAdded);
|
||||
if (in != null) {
|
||||
final IAEItemStack out = this.target.injectItems(in, Actionable.MODULATE, this.src);
|
||||
if (out != null) {
|
||||
return out.createItemStack();
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd( final ItemStack toBeSimulated )
|
||||
{
|
||||
final IAEItemStack in = AEItemStack.fromItemStack( toBeSimulated );
|
||||
if( in != null )
|
||||
{
|
||||
final IAEItemStack out = this.target.injectItems( in, Actionable.SIMULATE, this.src );
|
||||
if( out != null )
|
||||
{
|
||||
return out.createItemStack();
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public ItemStack simulateAdd(final ItemStack toBeSimulated) {
|
||||
final IAEItemStack in = AEItemStack.fromItemStack(toBeSimulated);
|
||||
if (in != null) {
|
||||
final IAEItemStack out = this.target.injectItems(in, Actionable.SIMULATE, this.src);
|
||||
if (out != null) {
|
||||
return out.createItemStack();
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
return !this.getList().isEmpty();
|
||||
}
|
||||
@Override
|
||||
public boolean containsItems() {
|
||||
return !this.getList().isEmpty();
|
||||
}
|
||||
|
||||
int getMaxSlots()
|
||||
{
|
||||
return this.maxSlots;
|
||||
}
|
||||
int getMaxSlots() {
|
||||
return this.maxSlots;
|
||||
}
|
||||
|
||||
void setMaxSlots( final int maxSlots )
|
||||
{
|
||||
this.maxSlots = maxSlots;
|
||||
}
|
||||
void setMaxSlots(final int maxSlots) {
|
||||
this.maxSlots = maxSlots;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,64 +19,56 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
public final class IMEAdaptorIterator implements Iterator<ItemSlot>
|
||||
{
|
||||
private final Iterator<IAEItemStack> stack;
|
||||
private final ItemSlot slot = new ItemSlot();
|
||||
private final IMEAdaptor parent;
|
||||
private final int containerSize;
|
||||
public final class IMEAdaptorIterator implements Iterator<ItemSlot> {
|
||||
private final Iterator<IAEItemStack> stack;
|
||||
private final ItemSlot slot = new ItemSlot();
|
||||
private final IMEAdaptor parent;
|
||||
private final int containerSize;
|
||||
|
||||
private int offset = 0;
|
||||
private boolean hasNext;
|
||||
private int offset = 0;
|
||||
private boolean hasNext;
|
||||
|
||||
public IMEAdaptorIterator( final IMEAdaptor parent, final IItemList<IAEItemStack> availableItems )
|
||||
{
|
||||
this.stack = availableItems.iterator();
|
||||
this.containerSize = parent.getMaxSlots();
|
||||
this.parent = parent;
|
||||
}
|
||||
public IMEAdaptorIterator(final IMEAdaptor parent, final IItemList<IAEItemStack> availableItems) {
|
||||
this.stack = availableItems.iterator();
|
||||
this.containerSize = parent.getMaxSlots();
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
this.hasNext = this.stack.hasNext();
|
||||
return this.offset < this.containerSize || this.hasNext;
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
this.hasNext = this.stack.hasNext();
|
||||
return this.offset < this.containerSize || this.hasNext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemSlot next()
|
||||
{
|
||||
this.slot.setSlot( this.offset );
|
||||
this.offset++;
|
||||
this.slot.setExtractable( true );
|
||||
@Override
|
||||
public ItemSlot next() {
|
||||
this.slot.setSlot(this.offset);
|
||||
this.offset++;
|
||||
this.slot.setExtractable(true);
|
||||
|
||||
if( this.parent.getMaxSlots() < this.offset )
|
||||
{
|
||||
this.parent.setMaxSlots( this.offset );
|
||||
}
|
||||
if (this.parent.getMaxSlots() < this.offset) {
|
||||
this.parent.setMaxSlots(this.offset);
|
||||
}
|
||||
|
||||
if( this.hasNext )
|
||||
{
|
||||
final IAEItemStack item = this.stack.next();
|
||||
this.slot.setAEItemStack( item );
|
||||
return this.slot;
|
||||
}
|
||||
if (this.hasNext) {
|
||||
final IAEItemStack item = this.stack.next();
|
||||
this.slot.setAEItemStack(item);
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
this.slot.setItemStack( ItemStack.EMPTY );
|
||||
return this.slot;
|
||||
}
|
||||
this.slot.setItemStack(ItemStack.EMPTY);
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,39 +19,33 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public class IMEInventoryDestination implements IInventoryDestination
|
||||
{
|
||||
public class IMEInventoryDestination implements IInventoryDestination {
|
||||
|
||||
private final IMEInventory<IAEItemStack> me;
|
||||
private final IMEInventory<IAEItemStack> me;
|
||||
|
||||
public IMEInventoryDestination( final IMEInventory<IAEItemStack> o )
|
||||
{
|
||||
this.me = o;
|
||||
}
|
||||
public IMEInventoryDestination(final IMEInventory<IAEItemStack> o) {
|
||||
this.me = o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert( final ItemStack stack )
|
||||
{
|
||||
@Override
|
||||
public boolean canInsert(final ItemStack stack) {
|
||||
|
||||
if( stack.isEmpty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (stack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final IAEItemStack failed = this.me.injectItems( AEItemStack.fromItemStack( stack ), Actionable.SIMULATE, null );
|
||||
final IAEItemStack failed = this.me.injectItems(AEItemStack.fromItemStack(stack), Actionable.SIMULATE, null);
|
||||
|
||||
if( failed == null )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return failed.getStackSize() != stack.getCount();
|
||||
}
|
||||
if (failed == null) {
|
||||
return true;
|
||||
}
|
||||
return failed.getStackSize() != stack.getCount();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
public enum InvOperation
|
||||
{
|
||||
EXTRACT, INSERT, SET
|
||||
public enum InvOperation {
|
||||
EXTRACT, INSERT, SET
|
||||
}
|
||||
|
||||
@@ -19,44 +19,39 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public class ItemHandlerIterator implements Iterator<ItemSlot> {
|
||||
|
||||
public class ItemHandlerIterator implements Iterator<ItemSlot>
|
||||
{
|
||||
private final IItemHandler itemHandler;
|
||||
|
||||
private final IItemHandler itemHandler;
|
||||
private final ItemSlot itemSlot = new ItemSlot();
|
||||
|
||||
private final ItemSlot itemSlot = new ItemSlot();
|
||||
private int slot = 0;
|
||||
|
||||
private int slot = 0;
|
||||
public ItemHandlerIterator(IItemHandler itemHandler) {
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
|
||||
public ItemHandlerIterator( IItemHandler itemHandler )
|
||||
{
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.slot < this.itemHandler.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return this.slot < this.itemHandler.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemSlot next()
|
||||
{
|
||||
if( this.slot >= this.itemHandler.getSlots() )
|
||||
{
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
this.itemSlot.setExtractable( !this.itemHandler.extractItem( this.slot, Integer.MAX_VALUE, true ).isEmpty() );
|
||||
this.itemSlot.setItemStack( this.itemHandler.getStackInSlot( this.slot ) );
|
||||
this.itemSlot.setSlot( this.slot );
|
||||
this.slot++;
|
||||
return this.itemSlot;
|
||||
}
|
||||
@Override
|
||||
public ItemSlot next() {
|
||||
if (this.slot >= this.itemHandler.getSlots()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
this.itemSlot.setExtractable(!this.itemHandler.extractItem(this.slot, Integer.MAX_VALUE, true).isEmpty());
|
||||
this.itemSlot.setItemStack(this.itemHandler.getStackInSlot(this.slot));
|
||||
this.itemSlot.setSlot(this.slot);
|
||||
this.slot++;
|
||||
return this.itemSlot;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,93 +19,79 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class ItemListIgnoreCrafting<T extends IAEStack<T>> implements IItemList<T>
|
||||
{
|
||||
|
||||
private final IItemList<T> target;
|
||||
public class ItemListIgnoreCrafting<T extends IAEStack<T>> implements IItemList<T> {
|
||||
|
||||
public ItemListIgnoreCrafting( final IItemList<T> cla )
|
||||
{
|
||||
this.target = cla;
|
||||
}
|
||||
private final IItemList<T> target;
|
||||
|
||||
@Override
|
||||
public void add( T option )
|
||||
{
|
||||
if( option != null && option.isCraftable() )
|
||||
{
|
||||
option = option.copy();
|
||||
option.setCraftable( false );
|
||||
}
|
||||
public ItemListIgnoreCrafting(final IItemList<T> cla) {
|
||||
this.target = cla;
|
||||
}
|
||||
|
||||
this.target.add( option );
|
||||
}
|
||||
@Override
|
||||
public void add(T option) {
|
||||
if (option != null && option.isCraftable()) {
|
||||
option = option.copy();
|
||||
option.setCraftable(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T findPrecise( final T i )
|
||||
{
|
||||
return this.target.findPrecise( i );
|
||||
}
|
||||
this.target.add(option);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<T> findFuzzy( final T input, final FuzzyMode fuzzy )
|
||||
{
|
||||
return this.target.findFuzzy( input, fuzzy );
|
||||
}
|
||||
@Override
|
||||
public T findPrecise(final T i) {
|
||||
return this.target.findPrecise(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return this.target.isEmpty();
|
||||
}
|
||||
@Override
|
||||
public Collection<T> findFuzzy(final T input, final FuzzyMode fuzzy) {
|
||||
return this.target.findFuzzy(input, fuzzy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStorage( final T option )
|
||||
{
|
||||
this.target.addStorage( option );
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.target.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCrafting( final T option )
|
||||
{
|
||||
// nothing.
|
||||
}
|
||||
@Override
|
||||
public void addStorage(final T option) {
|
||||
this.target.addStorage(option);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequestable( final T option )
|
||||
{
|
||||
this.target.addRequestable( option );
|
||||
}
|
||||
@Override
|
||||
public void addCrafting(final T option) {
|
||||
// nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getFirstItem()
|
||||
{
|
||||
return this.target.getFirstItem();
|
||||
}
|
||||
@Override
|
||||
public void addRequestable(final T option) {
|
||||
this.target.addRequestable(option);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return this.target.size();
|
||||
}
|
||||
@Override
|
||||
public T getFirstItem() {
|
||||
return this.target.getFirstItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator()
|
||||
{
|
||||
return this.target.iterator();
|
||||
}
|
||||
@Override
|
||||
public int size() {
|
||||
return this.target.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetStatus()
|
||||
{
|
||||
this.target.resetStatus();
|
||||
}
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return this.target.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetStatus() {
|
||||
this.target.resetStatus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,62 +19,52 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public class ItemSlot
|
||||
{
|
||||
public class ItemSlot {
|
||||
|
||||
private int slot;
|
||||
private boolean isExtractable;
|
||||
// one or the other..
|
||||
private IAEItemStack aeItemStack;
|
||||
private ItemStack itemStack;
|
||||
private int slot;
|
||||
private boolean isExtractable;
|
||||
// one or the other..
|
||||
private IAEItemStack aeItemStack;
|
||||
private ItemStack itemStack;
|
||||
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return this.itemStack
|
||||
.isEmpty() ? ( this.aeItemStack == null ? ItemStack.EMPTY : ( this.itemStack = this.aeItemStack.createItemStack() ) ) : this.itemStack;
|
||||
}
|
||||
public ItemStack getItemStack() {
|
||||
return this.itemStack
|
||||
.isEmpty() ? (this.aeItemStack == null ? ItemStack.EMPTY : (this.itemStack = this.aeItemStack.createItemStack())) : this.itemStack;
|
||||
}
|
||||
|
||||
public void setItemStack( final ItemStack is )
|
||||
{
|
||||
this.aeItemStack = null;
|
||||
this.itemStack = is;
|
||||
}
|
||||
public void setItemStack(final ItemStack is) {
|
||||
this.aeItemStack = null;
|
||||
this.itemStack = is;
|
||||
}
|
||||
|
||||
public IAEItemStack getAEItemStack()
|
||||
{
|
||||
return this.aeItemStack == null ? ( this.itemStack
|
||||
.isEmpty() ? null : ( this.aeItemStack = AEItemStack.fromItemStack( this.itemStack ) ) ) : this.aeItemStack;
|
||||
}
|
||||
public IAEItemStack getAEItemStack() {
|
||||
return this.aeItemStack == null ? (this.itemStack
|
||||
.isEmpty() ? null : (this.aeItemStack = AEItemStack.fromItemStack(this.itemStack))) : this.aeItemStack;
|
||||
}
|
||||
|
||||
void setAEItemStack( final IAEItemStack is )
|
||||
{
|
||||
this.aeItemStack = is;
|
||||
this.itemStack = ItemStack.EMPTY;
|
||||
}
|
||||
void setAEItemStack(final IAEItemStack is) {
|
||||
this.aeItemStack = is;
|
||||
this.itemStack = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public boolean isExtractable()
|
||||
{
|
||||
return this.isExtractable;
|
||||
}
|
||||
public boolean isExtractable() {
|
||||
return this.isExtractable;
|
||||
}
|
||||
|
||||
void setExtractable( final boolean isExtractable )
|
||||
{
|
||||
this.isExtractable = isExtractable;
|
||||
}
|
||||
void setExtractable(final boolean isExtractable) {
|
||||
this.isExtractable = isExtractable;
|
||||
}
|
||||
|
||||
public int getSlot()
|
||||
{
|
||||
return this.slot;
|
||||
}
|
||||
public int getSlot() {
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
public void setSlot( final int slot )
|
||||
{
|
||||
this.slot = slot;
|
||||
}
|
||||
public void setSlot(final int slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,152 +19,128 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import net.minecraftforge.items.wrapper.EmptyHandler;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class WrapperChainedItemHandler implements IItemHandlerModifiable
|
||||
{
|
||||
private IItemHandler[] itemHandler; // the handlers
|
||||
private int[] baseIndex; // index-offsets of the different handlers
|
||||
private int slotCount; // number of total slots
|
||||
public class WrapperChainedItemHandler implements IItemHandlerModifiable {
|
||||
private IItemHandler[] itemHandler; // the handlers
|
||||
private int[] baseIndex; // index-offsets of the different handlers
|
||||
private int slotCount; // number of total slots
|
||||
|
||||
public WrapperChainedItemHandler( IItemHandler... itemHandler )
|
||||
{
|
||||
this.setItemHandlers( itemHandler );
|
||||
}
|
||||
public WrapperChainedItemHandler(IItemHandler... itemHandler) {
|
||||
this.setItemHandlers(itemHandler);
|
||||
}
|
||||
|
||||
private void setItemHandlers( IItemHandler[] handlers )
|
||||
{
|
||||
this.itemHandler = handlers;
|
||||
this.baseIndex = new int[this.itemHandler.length];
|
||||
int index = 0;
|
||||
for( int i = 0; i < this.itemHandler.length; i++ )
|
||||
{
|
||||
index += this.itemHandler[i].getSlots();
|
||||
this.baseIndex[i] = index;
|
||||
}
|
||||
this.slotCount = index;
|
||||
}
|
||||
private void setItemHandlers(IItemHandler[] handlers) {
|
||||
this.itemHandler = handlers;
|
||||
this.baseIndex = new int[this.itemHandler.length];
|
||||
int index = 0;
|
||||
for (int i = 0; i < this.itemHandler.length; i++) {
|
||||
index += this.itemHandler[i].getSlots();
|
||||
this.baseIndex[i] = index;
|
||||
}
|
||||
this.slotCount = index;
|
||||
}
|
||||
|
||||
// returns the handler index for the slot
|
||||
private int getIndexForSlot( int slot )
|
||||
{
|
||||
if( slot < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
// returns the handler index for the slot
|
||||
private int getIndexForSlot(int slot) {
|
||||
if (slot < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for( int i = 0; i < this.baseIndex.length; i++ )
|
||||
{
|
||||
if( slot - this.baseIndex[i] < 0 )
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
for (int i = 0; i < this.baseIndex.length; i++) {
|
||||
if (slot - this.baseIndex[i] < 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private IItemHandler getHandlerFromIndex( int index )
|
||||
{
|
||||
if( index < 0 || index >= this.itemHandler.length )
|
||||
{
|
||||
return EmptyHandler.INSTANCE;
|
||||
}
|
||||
return this.itemHandler[index];
|
||||
}
|
||||
private IItemHandler getHandlerFromIndex(int index) {
|
||||
if (index < 0 || index >= this.itemHandler.length) {
|
||||
return EmptyHandler.INSTANCE;
|
||||
}
|
||||
return this.itemHandler[index];
|
||||
}
|
||||
|
||||
private int getSlotFromIndex( int slot, int index )
|
||||
{
|
||||
if( index <= 0 || index >= this.baseIndex.length )
|
||||
{
|
||||
return slot;
|
||||
}
|
||||
return slot - this.baseIndex[index - 1];
|
||||
}
|
||||
private int getSlotFromIndex(int slot, int index) {
|
||||
if (index <= 0 || index >= this.baseIndex.length) {
|
||||
return slot;
|
||||
}
|
||||
return slot - this.baseIndex[index - 1];
|
||||
}
|
||||
|
||||
public void cycleOrder()
|
||||
{
|
||||
if( this.itemHandler.length > 1 )
|
||||
{
|
||||
ArrayList<IItemHandler> newOrder = new ArrayList<>();
|
||||
newOrder.add( this.itemHandler[this.itemHandler.length - 1] );
|
||||
for( int i = 0; i < this.itemHandler.length - 1; ++i )
|
||||
{
|
||||
newOrder.add( this.itemHandler[i] );
|
||||
}
|
||||
this.setItemHandlers( newOrder.toArray( new IItemHandler[this.itemHandler.length] ) );
|
||||
}
|
||||
}
|
||||
public void cycleOrder() {
|
||||
if (this.itemHandler.length > 1) {
|
||||
ArrayList<IItemHandler> newOrder = new ArrayList<>();
|
||||
newOrder.add(this.itemHandler[this.itemHandler.length - 1]);
|
||||
for (int i = 0; i < this.itemHandler.length - 1; ++i) {
|
||||
newOrder.add(this.itemHandler[i]);
|
||||
}
|
||||
this.setItemHandlers(newOrder.toArray(new IItemHandler[this.itemHandler.length]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return this.slotCount;
|
||||
}
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return this.slotCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack getStackInSlot( final int slot )
|
||||
{
|
||||
int index = this.getIndexForSlot( slot );
|
||||
IItemHandler handler = this.getHandlerFromIndex( index );
|
||||
int targetSlot = this.getSlotFromIndex( slot, index );
|
||||
return handler.getStackInSlot( targetSlot );
|
||||
}
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack getStackInSlot(final int slot) {
|
||||
int index = this.getIndexForSlot(slot);
|
||||
IItemHandler handler = this.getHandlerFromIndex(index);
|
||||
int targetSlot = this.getSlotFromIndex(slot, index);
|
||||
return handler.getStackInSlot(targetSlot);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack insertItem( final int slot, @Nonnull ItemStack stack, boolean simulate )
|
||||
{
|
||||
int index = this.getIndexForSlot( slot );
|
||||
IItemHandler handler = this.getHandlerFromIndex( index );
|
||||
int targetSlot = this.getSlotFromIndex( slot, index );
|
||||
return handler.insertItem( targetSlot, stack, simulate );
|
||||
}
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack insertItem(final int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||
int index = this.getIndexForSlot(slot);
|
||||
IItemHandler handler = this.getHandlerFromIndex(index);
|
||||
int targetSlot = this.getSlotFromIndex(slot, index);
|
||||
return handler.insertItem(targetSlot, stack, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack extractItem( int slot, int amount, boolean simulate )
|
||||
{
|
||||
int index = this.getIndexForSlot( slot );
|
||||
IItemHandler handler = this.getHandlerFromIndex( index );
|
||||
int targetSlot = this.getSlotFromIndex( slot, index );
|
||||
return handler.extractItem( targetSlot, amount, simulate );
|
||||
}
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
int index = this.getIndexForSlot(slot);
|
||||
IItemHandler handler = this.getHandlerFromIndex(index);
|
||||
int targetSlot = this.getSlotFromIndex(slot, index);
|
||||
return handler.extractItem(targetSlot, amount, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit( int slot )
|
||||
{
|
||||
int index = this.getIndexForSlot( slot );
|
||||
IItemHandler handler = this.getHandlerFromIndex( index );
|
||||
int localSlot = this.getSlotFromIndex( slot, index );
|
||||
return handler.getSlotLimit( localSlot );
|
||||
}
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
int index = this.getIndexForSlot(slot);
|
||||
IItemHandler handler = this.getHandlerFromIndex(index);
|
||||
int localSlot = this.getSlotFromIndex(slot, index);
|
||||
return handler.getSlotLimit(localSlot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot( int slot, ItemStack stack )
|
||||
{
|
||||
int index = this.getIndexForSlot( slot );
|
||||
IItemHandler handler = this.getHandlerFromIndex( index );
|
||||
int targetSlot = this.getSlotFromIndex( slot, index );
|
||||
ItemHandlerUtil.setStackInSlot( handler, targetSlot, stack );
|
||||
}
|
||||
@Override
|
||||
public void setStackInSlot(int slot, ItemStack stack) {
|
||||
int index = this.getIndexForSlot(slot);
|
||||
IItemHandler handler = this.getHandlerFromIndex(index);
|
||||
int targetSlot = this.getSlotFromIndex(slot, index);
|
||||
ItemHandlerUtil.setStackInSlot(handler, targetSlot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid( int slot, ItemStack stack )
|
||||
{
|
||||
int index = this.getIndexForSlot( slot );
|
||||
IItemHandler handler = this.getHandlerFromIndex( index );
|
||||
int targetSlot = this.getSlotFromIndex( slot, index );
|
||||
return handler.isItemValid( targetSlot, stack );
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValid(int slot, ItemStack stack) {
|
||||
int index = this.getIndexForSlot(slot);
|
||||
IItemHandler handler = this.getHandlerFromIndex(index);
|
||||
int targetSlot = this.getSlotFromIndex(slot, index);
|
||||
return handler.isItemValid(targetSlot, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,21 +23,18 @@ import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
|
||||
public class WrapperCursorItemHandler extends ItemStackHandler
|
||||
{
|
||||
private final InventoryPlayer inv;
|
||||
public class WrapperCursorItemHandler extends ItemStackHandler {
|
||||
private final InventoryPlayer inv;
|
||||
|
||||
public WrapperCursorItemHandler( InventoryPlayer inventoryPlayer )
|
||||
{
|
||||
super( 1 );
|
||||
public WrapperCursorItemHandler(InventoryPlayer inventoryPlayer) {
|
||||
super(1);
|
||||
|
||||
this.inv = inventoryPlayer;
|
||||
this.setStackInSlot( 0, inventoryPlayer.getItemStack() );
|
||||
}
|
||||
this.inv = inventoryPlayer;
|
||||
this.setStackInSlot(0, inventoryPlayer.getItemStack());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onContentsChanged( int slot )
|
||||
{
|
||||
this.inv.setItemStack( this.getStackInSlot( slot ) );
|
||||
}
|
||||
@Override
|
||||
protected void onContentsChanged(int slot) {
|
||||
this.inv.setItemStack(this.getStackInSlot(slot));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,80 +19,67 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
||||
public class WrapperFilteredItemHandler implements IItemHandlerModifiable
|
||||
{
|
||||
private final IItemHandler handler;
|
||||
private final IAEItemFilter filter;
|
||||
public class WrapperFilteredItemHandler implements IItemHandlerModifiable {
|
||||
private final IItemHandler handler;
|
||||
private final IAEItemFilter filter;
|
||||
|
||||
public WrapperFilteredItemHandler( @Nonnull IItemHandler handler, @Nonnull IAEItemFilter filter )
|
||||
{
|
||||
this.handler = handler;
|
||||
this.filter = filter;
|
||||
}
|
||||
public WrapperFilteredItemHandler(@Nonnull IItemHandler handler, @Nonnull IAEItemFilter filter) {
|
||||
this.handler = handler;
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot( int slot, ItemStack stack )
|
||||
{
|
||||
ItemHandlerUtil.setStackInSlot( this.handler, slot, stack );
|
||||
}
|
||||
@Override
|
||||
public void setStackInSlot(int slot, ItemStack stack) {
|
||||
ItemHandlerUtil.setStackInSlot(this.handler, slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return this.handler.getSlots();
|
||||
}
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return this.handler.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( int slot )
|
||||
{
|
||||
return this.handler.getStackInSlot( slot );
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return this.handler.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack insertItem( int slot, ItemStack stack, boolean simulate )
|
||||
{
|
||||
if( !this.filter.allowInsert( this.handler, slot, stack ) )
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
||||
if (!this.filter.allowInsert(this.handler, slot, stack)) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
return this.handler.insertItem( slot, stack, simulate );
|
||||
}
|
||||
return this.handler.insertItem(slot, stack, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack extractItem( int slot, int amount, boolean simulate )
|
||||
{
|
||||
if( !this.filter.allowExtract( this.handler, slot, amount ) )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
if (!this.filter.allowExtract(this.handler, slot, amount)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return this.handler.extractItem( slot, amount, simulate );
|
||||
}
|
||||
return this.handler.extractItem(slot, amount, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit( int slot )
|
||||
{
|
||||
return this.handler.getSlotLimit( slot );
|
||||
}
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
return this.handler.getSlotLimit(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid( int slot, ItemStack stack )
|
||||
{
|
||||
if( !this.filter.allowInsert( this.handler, slot, stack ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this.handler.isItemValid( slot, stack );
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValid(int slot, ItemStack stack) {
|
||||
if (!this.filter.allowInsert(this.handler, slot, stack)) {
|
||||
return false;
|
||||
}
|
||||
return this.handler.isItemValid(slot, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,141 +19,118 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
|
||||
public class WrapperInvItemHandler implements IInventory {
|
||||
private final IItemHandler inv;
|
||||
|
||||
public class WrapperInvItemHandler implements IInventory
|
||||
{
|
||||
private final IItemHandler inv;
|
||||
public WrapperInvItemHandler(final IItemHandler inv) {
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
public WrapperInvItemHandler( final IItemHandler inv )
|
||||
{
|
||||
this.inv = inv;
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public boolean hasCustomName() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public ITextComponent getDisplayName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return this.inv.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.inv.getSlots();
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return ItemHandlerUtil.isEmpty(this.inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return ItemHandlerUtil.isEmpty( this.inv );
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int index) {
|
||||
return this.inv.getStackInSlot(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( int index )
|
||||
{
|
||||
return this.inv.getStackInSlot( index );
|
||||
}
|
||||
@Override
|
||||
public ItemStack decrStackSize(int index, int count) {
|
||||
return this.inv.extractItem(index, count, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize( int index, int count )
|
||||
{
|
||||
return this.inv.extractItem( index, count, false );
|
||||
}
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int index) {
|
||||
return this.inv.extractItem(index, this.inv.getSlotLimit(index), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot( int index )
|
||||
{
|
||||
return this.inv.extractItem( index, this.inv.getSlotLimit( index ), false );
|
||||
}
|
||||
@Override
|
||||
public void setInventorySlotContents(int index, ItemStack stack) {
|
||||
ItemHandlerUtil.setStackInSlot(this.inv, index, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents( int index, ItemStack stack )
|
||||
{
|
||||
ItemHandlerUtil.setStackInSlot( this.inv, index, stack );
|
||||
}
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
int max = 0;
|
||||
for (int i = 0; i < this.inv.getSlots(); ++i) {
|
||||
max = Math.max(max, this.inv.getSlotLimit(i));
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
int max = 0;
|
||||
for( int i = 0; i < this.inv.getSlots(); ++i )
|
||||
{
|
||||
max = Math.max( max, this.inv.getSlotLimit( i ) );
|
||||
}
|
||||
return max;
|
||||
}
|
||||
@Override
|
||||
public void markDirty() {
|
||||
// NOP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
// NOP
|
||||
}
|
||||
@Override
|
||||
public boolean isUsableByPlayer(EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer( EntityPlayer player )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void openInventory(EntityPlayer player) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory( EntityPlayer player )
|
||||
{
|
||||
// NOP
|
||||
}
|
||||
@Override
|
||||
public void closeInventory(EntityPlayer player) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory( EntityPlayer player )
|
||||
{
|
||||
// NOP
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int index, ItemStack stack) {
|
||||
return this.inv.isItemValid(index, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int index, ItemStack stack )
|
||||
{
|
||||
return this.inv.isItemValid( index, stack );
|
||||
}
|
||||
@Override
|
||||
public int getField(int id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField( int id )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public void setField(int id, int value) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField( int id, int value )
|
||||
{
|
||||
// NOP
|
||||
}
|
||||
@Override
|
||||
public int getFieldCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
ItemHandlerUtil.clear( this.inv );
|
||||
}
|
||||
@Override
|
||||
public void clear() {
|
||||
ItemHandlerUtil.clear(this.inv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,102 +19,85 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
|
||||
public class WrapperRangeItemHandler implements IItemHandlerModifiable
|
||||
{
|
||||
private final IItemHandler compose;
|
||||
private final int minSlot;
|
||||
private final int maxSlot;
|
||||
public class WrapperRangeItemHandler implements IItemHandlerModifiable {
|
||||
private final IItemHandler compose;
|
||||
private final int minSlot;
|
||||
private final int maxSlot;
|
||||
|
||||
public WrapperRangeItemHandler( IItemHandler compose, int minSlot, int maxSlotExclusive )
|
||||
{
|
||||
this.compose = compose;
|
||||
this.minSlot = minSlot;
|
||||
this.maxSlot = maxSlotExclusive;
|
||||
}
|
||||
public WrapperRangeItemHandler(IItemHandler compose, int minSlot, int maxSlotExclusive) {
|
||||
this.compose = compose;
|
||||
this.minSlot = minSlot;
|
||||
this.maxSlot = maxSlotExclusive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return this.maxSlot - this.minSlot;
|
||||
}
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return this.maxSlot - this.minSlot;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack getStackInSlot( int slot )
|
||||
{
|
||||
if( this.checkSlot( slot ) )
|
||||
{
|
||||
return this.compose.getStackInSlot( slot + this.minSlot );
|
||||
}
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
if (this.checkSlot(slot)) {
|
||||
return this.compose.getStackInSlot(slot + this.minSlot);
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack insertItem( int slot, @Nonnull ItemStack stack, boolean simulate )
|
||||
{
|
||||
if( this.checkSlot( slot ) )
|
||||
{
|
||||
return this.compose.insertItem( slot + this.minSlot, stack, simulate );
|
||||
}
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||
if (this.checkSlot(slot)) {
|
||||
return this.compose.insertItem(slot + this.minSlot, stack, simulate);
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack extractItem( int slot, int amount, boolean simulate )
|
||||
{
|
||||
if( this.checkSlot( slot ) )
|
||||
{
|
||||
return this.compose.extractItem( slot + this.minSlot, amount, simulate );
|
||||
}
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
if (this.checkSlot(slot)) {
|
||||
return this.compose.extractItem(slot + this.minSlot, amount, simulate);
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot( int slot, @Nonnull ItemStack stack )
|
||||
{
|
||||
if( this.checkSlot( slot ) )
|
||||
{
|
||||
ItemHandlerUtil.setStackInSlot( this.compose, slot + this.minSlot, stack );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void setStackInSlot(int slot, @Nonnull ItemStack stack) {
|
||||
if (this.checkSlot(slot)) {
|
||||
ItemHandlerUtil.setStackInSlot(this.compose, slot + this.minSlot, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit( int slot )
|
||||
{
|
||||
if( this.checkSlot( slot ) )
|
||||
{
|
||||
return this.compose.getSlotLimit( slot + this.minSlot );
|
||||
}
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
if (this.checkSlot(slot)) {
|
||||
return this.compose.getSlotLimit(slot + this.minSlot);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private boolean checkSlot( int localSlot )
|
||||
{
|
||||
return localSlot + this.minSlot < this.maxSlot;
|
||||
}
|
||||
private boolean checkSlot(int localSlot) {
|
||||
return localSlot + this.minSlot < this.maxSlot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid( int slot, ItemStack stack )
|
||||
{
|
||||
if( this.checkSlot( slot ) )
|
||||
{
|
||||
return this.compose.isItemValid( slot + this.minSlot, stack );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValid(int slot, ItemStack stack) {
|
||||
if (this.checkSlot(slot)) {
|
||||
return this.compose.isItemValid(slot + this.minSlot, stack);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,63 +19,53 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
public class WrapperSupplierItemHandler implements IItemHandlerModifiable
|
||||
{
|
||||
private final Supplier<IItemHandler> sourceHandler;
|
||||
public class WrapperSupplierItemHandler implements IItemHandlerModifiable {
|
||||
private final Supplier<IItemHandler> sourceHandler;
|
||||
|
||||
public WrapperSupplierItemHandler( Supplier<IItemHandler> source )
|
||||
{
|
||||
this.sourceHandler = source;
|
||||
}
|
||||
public WrapperSupplierItemHandler(Supplier<IItemHandler> source) {
|
||||
this.sourceHandler = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return this.sourceHandler.get().getSlots();
|
||||
}
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return this.sourceHandler.get().getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( int slot )
|
||||
{
|
||||
return this.sourceHandler.get().getStackInSlot( slot );
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return this.sourceHandler.get().getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack insertItem( int slot, ItemStack stack, boolean simulate )
|
||||
{
|
||||
return this.sourceHandler.get().insertItem( slot, stack, simulate );
|
||||
}
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
||||
return this.sourceHandler.get().insertItem(slot, stack, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack extractItem( int slot, int amount, boolean simulate )
|
||||
{
|
||||
return this.sourceHandler.get().extractItem( slot, amount, simulate );
|
||||
}
|
||||
@Override
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
return this.sourceHandler.get().extractItem(slot, amount, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit( int slot )
|
||||
{
|
||||
return this.sourceHandler.get().getSlotLimit( slot );
|
||||
}
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
return this.sourceHandler.get().getSlotLimit(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot( int slot, ItemStack stack )
|
||||
{
|
||||
ItemHandlerUtil.setStackInSlot( this.sourceHandler.get(), slot, stack );
|
||||
}
|
||||
@Override
|
||||
public void setStackInSlot(int slot, ItemStack stack) {
|
||||
ItemHandlerUtil.setStackInSlot(this.sourceHandler.get(), slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid( int slot, ItemStack stack )
|
||||
{
|
||||
return this.sourceHandler.get().isItemValid( slot, stack );
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValid(int slot, ItemStack stack) {
|
||||
return this.sourceHandler.get().isItemValid(slot, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,31 +19,26 @@
|
||||
package appeng.util.inv.filter;
|
||||
|
||||
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
|
||||
public class AEItemDefinitionFilter implements IAEItemFilter {
|
||||
private final IItemDefinition definition;
|
||||
|
||||
public class AEItemDefinitionFilter implements IAEItemFilter
|
||||
{
|
||||
private final IItemDefinition definition;
|
||||
public AEItemDefinitionFilter(IItemDefinition definition) {
|
||||
this.definition = definition;
|
||||
}
|
||||
|
||||
public AEItemDefinitionFilter( IItemDefinition definition )
|
||||
{
|
||||
this.definition = definition;
|
||||
}
|
||||
@Override
|
||||
public boolean allowExtract(IItemHandler inv, int slot, int amount) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowExtract( IItemHandler inv, int slot, int amount )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
|
||||
{
|
||||
return this.definition.isSameAs( stack );
|
||||
}
|
||||
@Override
|
||||
public boolean allowInsert(IItemHandler inv, int slot, ItemStack stack) {
|
||||
return this.definition.isSameAs(stack);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,42 +23,34 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
|
||||
public class AEItemFilters
|
||||
{
|
||||
public static final IAEItemFilter INSERT_ONLY = new InsertOnlyFilter();
|
||||
public static final IAEItemFilter EXTRACT_ONLY = new ExtractOnlyFilter();
|
||||
public class AEItemFilters {
|
||||
public static final IAEItemFilter INSERT_ONLY = new InsertOnlyFilter();
|
||||
public static final IAEItemFilter EXTRACT_ONLY = new ExtractOnlyFilter();
|
||||
|
||||
private AEItemFilters()
|
||||
{
|
||||
}
|
||||
private AEItemFilters() {
|
||||
}
|
||||
|
||||
private static class InsertOnlyFilter implements IAEItemFilter
|
||||
{
|
||||
@Override
|
||||
public boolean allowExtract( IItemHandler inv, int slot, int amount )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
private static class InsertOnlyFilter implements IAEItemFilter {
|
||||
@Override
|
||||
public boolean allowExtract(IItemHandler inv, int slot, int amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean allowInsert(IItemHandler inv, int slot, ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ExtractOnlyFilter implements IAEItemFilter
|
||||
{
|
||||
@Override
|
||||
public boolean allowExtract( IItemHandler inv, int slot, int amount )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
private static class ExtractOnlyFilter implements IAEItemFilter {
|
||||
@Override
|
||||
public boolean allowExtract(IItemHandler inv, int slot, int amount) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean allowInsert(IItemHandler inv, int slot, ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,8 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
|
||||
public interface IAEItemFilter
|
||||
{
|
||||
boolean allowExtract( IItemHandler inv, int slot, int amount );
|
||||
public interface IAEItemFilter {
|
||||
boolean allowExtract(IItemHandler inv, int slot, int amount);
|
||||
|
||||
boolean allowInsert( IItemHandler inv, int slot, ItemStack stack );
|
||||
boolean allowInsert(IItemHandler inv, int slot, ItemStack stack);
|
||||
}
|
||||
|
||||
@@ -18,13 +18,12 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.core.Api;
|
||||
import appeng.util.Platform;
|
||||
import com.google.common.primitives.Ints;
|
||||
import gregtech.api.items.IToolItem;
|
||||
import ic2.api.item.ICustomDamageItem;
|
||||
@@ -37,385 +36,317 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.core.Api;
|
||||
import appeng.util.Platform;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack
|
||||
{
|
||||
private static final String NBT_STACKSIZE = "Cnt";
|
||||
private static final String NBT_REQUESTABLE = "Req";
|
||||
private static final String NBT_CRAFTABLE = "Craft";
|
||||
public class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack {
|
||||
private static final String NBT_STACKSIZE = "Cnt";
|
||||
private static final String NBT_REQUESTABLE = "Req";
|
||||
private static final String NBT_CRAFTABLE = "Craft";
|
||||
|
||||
private final AESharedItemStack sharedStack;
|
||||
private Optional<OreReference> oreReference;
|
||||
private final AESharedItemStack sharedStack;
|
||||
private final Optional<OreReference> oreReference;
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
private String displayName;
|
||||
@SideOnly( Side.CLIENT )
|
||||
private List<String> tooltip;
|
||||
private ItemStack cachedItemStack;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private String displayName;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private List<String> tooltip;
|
||||
private ItemStack cachedItemStack;
|
||||
|
||||
private AEItemStack( final AEItemStack is )
|
||||
{
|
||||
this.setStackSize( is.getStackSize() );
|
||||
this.setCraftable( is.isCraftable() );
|
||||
this.setCountRequestable( is.getCountRequestable() );
|
||||
this.sharedStack = is.sharedStack;
|
||||
this.oreReference = is.oreReference;
|
||||
this.cachedItemStack = is.cachedItemStack;
|
||||
}
|
||||
private AEItemStack(final AEItemStack is) {
|
||||
this.setStackSize(is.getStackSize());
|
||||
this.setCraftable(is.isCraftable());
|
||||
this.setCountRequestable(is.getCountRequestable());
|
||||
this.sharedStack = is.sharedStack;
|
||||
this.oreReference = is.oreReference;
|
||||
this.cachedItemStack = is.cachedItemStack;
|
||||
}
|
||||
|
||||
private AEItemStack( final AESharedItemStack is, long size )
|
||||
{
|
||||
this.sharedStack = is;
|
||||
this.setStackSize( size );
|
||||
this.setCraftable( false );
|
||||
this.setCountRequestable( 0 );
|
||||
this.oreReference = OreHelper.INSTANCE.getOre( is.getDefinition() );
|
||||
}
|
||||
private AEItemStack(final AESharedItemStack is, long size) {
|
||||
this.sharedStack = is;
|
||||
this.setStackSize(size);
|
||||
this.setCraftable(false);
|
||||
this.setCountRequestable(0);
|
||||
this.oreReference = OreHelper.INSTANCE.getOre(is.getDefinition());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static AEItemStack fromItemStack( @Nonnull final ItemStack stack )
|
||||
{
|
||||
if( stack.isEmpty() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Nullable
|
||||
public static AEItemStack fromItemStack(@Nonnull final ItemStack stack) {
|
||||
if (stack.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new AEItemStack( AEItemStackRegistry.getRegisteredStack( stack ), stack.getCount() );
|
||||
}
|
||||
return new AEItemStack(AEItemStackRegistry.getRegisteredStack(stack), stack.getCount());
|
||||
}
|
||||
|
||||
public static IAEItemStack fromNBT( final NBTTagCompound i )
|
||||
{
|
||||
if( i == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
public static IAEItemStack fromNBT(final NBTTagCompound i) {
|
||||
if (i == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final ItemStack itemstack = new ItemStack( i );
|
||||
if( itemstack.isEmpty() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
final ItemStack itemstack = new ItemStack(i);
|
||||
if (itemstack.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final AEItemStack item = AEItemStack.fromItemStack( itemstack );
|
||||
final AEItemStack item = AEItemStack.fromItemStack(itemstack);
|
||||
|
||||
item.setStackSize( i.getLong( NBT_STACKSIZE ) );
|
||||
item.setCountRequestable( i.getLong( NBT_REQUESTABLE ) );
|
||||
item.setCraftable( i.getBoolean( NBT_CRAFTABLE ) );
|
||||
return item;
|
||||
}
|
||||
item.setStackSize(i.getLong(NBT_STACKSIZE));
|
||||
item.setCountRequestable(i.getLong(NBT_REQUESTABLE));
|
||||
item.setCraftable(i.getBoolean(NBT_CRAFTABLE));
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final NBTTagCompound i )
|
||||
{
|
||||
this.getDefinition().writeToNBT( i );
|
||||
@Override
|
||||
public void writeToNBT(final NBTTagCompound i) {
|
||||
this.getDefinition().writeToNBT(i);
|
||||
|
||||
i.setLong( NBT_STACKSIZE, this.getStackSize() );
|
||||
i.setLong( NBT_REQUESTABLE, this.getCountRequestable() );
|
||||
i.setBoolean( NBT_CRAFTABLE, this.isCraftable() );
|
||||
}
|
||||
i.setLong(NBT_STACKSIZE, this.getStackSize());
|
||||
i.setLong(NBT_REQUESTABLE, this.getCountRequestable());
|
||||
i.setBoolean(NBT_CRAFTABLE, this.isCraftable());
|
||||
}
|
||||
|
||||
public static AEItemStack fromPacket( final ByteBuf data )
|
||||
{
|
||||
final byte mask = data.readByte();
|
||||
final byte stackType = (byte) ( ( mask & 0x0C ) >> 2 );
|
||||
final byte countReqType = (byte) ( ( mask & 0x30 ) >> 4 );
|
||||
final boolean isCraftable = ( mask & 0x40 ) > 0;
|
||||
public static AEItemStack fromPacket(final ByteBuf data) {
|
||||
final byte mask = data.readByte();
|
||||
final byte stackType = (byte) ((mask & 0x0C) >> 2);
|
||||
final byte countReqType = (byte) ((mask & 0x30) >> 4);
|
||||
final boolean isCraftable = (mask & 0x40) > 0;
|
||||
|
||||
final ItemStack itemstack = new ItemStack( ByteBufUtils.readTag( data ) );
|
||||
final long stackSize = getPacketValue( stackType, data );
|
||||
final long countRequestable = getPacketValue( countReqType, data );
|
||||
final ItemStack itemstack = new ItemStack(ByteBufUtils.readTag(data));
|
||||
final long stackSize = getPacketValue(stackType, data);
|
||||
final long countRequestable = getPacketValue(countReqType, data);
|
||||
|
||||
if( itemstack.isEmpty() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (itemstack.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final AEItemStack item = new AEItemStack( AEItemStackRegistry.getRegisteredStack( itemstack ), stackSize );
|
||||
item.setCountRequestable( countRequestable );
|
||||
item.setCraftable( isCraftable );
|
||||
return item;
|
||||
}
|
||||
final AEItemStack item = new AEItemStack(AEItemStackRegistry.getRegisteredStack(itemstack), stackSize);
|
||||
item.setCountRequestable(countRequestable);
|
||||
item.setCraftable(isCraftable);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToPacket( final ByteBuf i )
|
||||
{
|
||||
final byte mask = (byte) ( ( this.getType( this.getStackSize() ) << 2 ) | ( this.getType( this.getCountRequestable() ) << 4 ) | ( (byte) ( this.isCraftable() ? 1 : 0 ) << 6 ) | ( this.hasTagCompound() ? 1 : 0 ) << 7 );
|
||||
@Override
|
||||
public void writeToPacket(final ByteBuf i) {
|
||||
final byte mask = (byte) ((this.getType(this.getStackSize()) << 2) | (this.getType(this.getCountRequestable()) << 4) | ((byte) (this.isCraftable() ? 1 : 0) << 6) | (this.hasTagCompound() ? 1 : 0) << 7);
|
||||
|
||||
i.writeByte( mask );
|
||||
ByteBufUtils.writeTag( i, this.getDefinition().serializeNBT() );
|
||||
this.putPacketValue( i, this.getStackSize() );
|
||||
this.putPacketValue( i, this.getCountRequestable() );
|
||||
}
|
||||
i.writeByte(mask);
|
||||
ByteBufUtils.writeTag(i, this.getDefinition().serializeNBT());
|
||||
this.putPacketValue(i, this.getStackSize());
|
||||
this.putPacketValue(i, this.getCountRequestable());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add( final IAEItemStack option )
|
||||
{
|
||||
if( option == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
public void add(final IAEItemStack option) {
|
||||
if (option == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.incStackSize( option.getStackSize() );
|
||||
this.setCountRequestable( this.getCountRequestable() + option.getCountRequestable() );
|
||||
this.setCraftable( this.isCraftable() || option.isCraftable() );
|
||||
}
|
||||
this.incStackSize(option.getStackSize());
|
||||
this.setCountRequestable(this.getCountRequestable() + option.getCountRequestable());
|
||||
this.setCraftable(this.isCraftable() || option.isCraftable());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fuzzyComparison( final IAEItemStack other, final FuzzyMode mode )
|
||||
{
|
||||
final ItemStack itemStack = this.getDefinition();
|
||||
final ItemStack otherStack = other.getDefinition();
|
||||
@Override
|
||||
public boolean fuzzyComparison(final IAEItemStack other, final FuzzyMode mode) {
|
||||
final ItemStack itemStack = this.getDefinition();
|
||||
final ItemStack otherStack = other.getDefinition();
|
||||
|
||||
return this.fuzzyItemStackComparison( itemStack, otherStack, mode );
|
||||
}
|
||||
return this.fuzzyItemStackComparison(itemStack, otherStack, mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack copy()
|
||||
{
|
||||
return new AEItemStack( this );
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack copy() {
|
||||
return new AEItemStack(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItem()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isItem() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFluid()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isFluid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel()
|
||||
{
|
||||
return Api.INSTANCE.storage().getStorageChannel( IItemStorageChannel.class );
|
||||
}
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel() {
|
||||
return Api.INSTANCE.storage().getStorageChannel(IItemStorageChannel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack createItemStack()
|
||||
{
|
||||
return ItemHandlerHelper.copyStackWithSize( this.getDefinition(), (int) Math.min( Integer.MAX_VALUE, this.getStackSize() ) );
|
||||
}
|
||||
@Override
|
||||
public ItemStack createItemStack() {
|
||||
return ItemHandlerHelper.copyStackWithSize(this.getDefinition(), (int) Math.min(Integer.MAX_VALUE, this.getStackSize()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getItem()
|
||||
{
|
||||
return this.getDefinition().getItem();
|
||||
}
|
||||
@Override
|
||||
public Item getItem() {
|
||||
return this.getDefinition().getItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemDamage()
|
||||
{
|
||||
return this.sharedStack.getItemDamage();
|
||||
}
|
||||
@Override
|
||||
public int getItemDamage() {
|
||||
return this.sharedStack.getItemDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sameOre( final IAEItemStack is )
|
||||
{
|
||||
return OreHelper.INSTANCE.sameOre( this, is );
|
||||
}
|
||||
@Override
|
||||
public boolean sameOre(final IAEItemStack is) {
|
||||
return OreHelper.INSTANCE.sameOre(this, is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameType( final IAEItemStack otherStack )
|
||||
{
|
||||
if( otherStack == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isSameType(final IAEItemStack otherStack) {
|
||||
if (otherStack == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Objects.equals( this.sharedStack, ( (AEItemStack) otherStack ).sharedStack );
|
||||
}
|
||||
return Objects.equals(this.sharedStack, ((AEItemStack) otherStack).sharedStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameType( final ItemStack otherStack )
|
||||
{
|
||||
if( otherStack.isEmpty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
int oldSize = otherStack.getCount();
|
||||
@Override
|
||||
public boolean isSameType(final ItemStack otherStack) {
|
||||
if (otherStack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
int oldSize = otherStack.getCount();
|
||||
|
||||
otherStack.setCount( 1 );
|
||||
boolean ret = ItemStack.areItemStacksEqual( this.getDefinition(), otherStack );
|
||||
otherStack.setCount( oldSize );
|
||||
otherStack.setCount(1);
|
||||
boolean ret = ItemStack.areItemStacksEqual(this.getDefinition(), otherStack);
|
||||
otherStack.setCount(oldSize);
|
||||
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return this.sharedStack.hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.sharedStack.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( final Object ia )
|
||||
{
|
||||
if( ia instanceof AEItemStack )
|
||||
{
|
||||
return this.isSameType( (AEItemStack) ia );
|
||||
}
|
||||
else if( ia instanceof ItemStack )
|
||||
{
|
||||
// this actually breaks the equals contract (being equals to unrelated classes)
|
||||
return equals( (ItemStack) ia );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final Object ia) {
|
||||
if (ia instanceof AEItemStack) {
|
||||
return this.isSameType((AEItemStack) ia);
|
||||
} else if (ia instanceof ItemStack) {
|
||||
// this actually breaks the equals contract (being equals to unrelated classes)
|
||||
return equals((ItemStack) ia);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( final ItemStack is )
|
||||
{
|
||||
return this.isSameType( is );
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final ItemStack is) {
|
||||
return this.isSameType(is);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCachedItemStack( long stackSize )
|
||||
{
|
||||
if( this.cachedItemStack != null )
|
||||
{
|
||||
ItemStack currentCached = this.cachedItemStack;
|
||||
this.cachedItemStack = null;
|
||||
currentCached.setCount( Ints.saturatedCast( stackSize ) );
|
||||
return currentCached;
|
||||
}
|
||||
@Override
|
||||
public ItemStack getCachedItemStack(long stackSize) {
|
||||
if (this.cachedItemStack != null) {
|
||||
ItemStack currentCached = this.cachedItemStack;
|
||||
this.cachedItemStack = null;
|
||||
currentCached.setCount(Ints.saturatedCast(stackSize));
|
||||
return currentCached;
|
||||
}
|
||||
|
||||
ItemStack itemStack = this.createItemStack();
|
||||
itemStack.setCount( Ints.saturatedCast( stackSize ) );
|
||||
ItemStack itemStack = this.createItemStack();
|
||||
itemStack.setCount(Ints.saturatedCast(stackSize));
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCachedItemStack( ItemStack itemStack )
|
||||
{
|
||||
this.cachedItemStack = itemStack;
|
||||
}
|
||||
@Override
|
||||
public void setCachedItemStack(ItemStack itemStack) {
|
||||
this.cachedItemStack = itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.getStackSize() + "x" + this.getDefinition().getItem().getRegistryName();
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getStackSize() + "x" + this.getDefinition().getItem().getRegistryName();
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
public List<String> getToolTip()
|
||||
{
|
||||
if( this.tooltip == null )
|
||||
{
|
||||
this.tooltip = Platform.getTooltip( this.asItemStackRepresentation() );
|
||||
}
|
||||
return this.tooltip;
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
public List<String> getToolTip() {
|
||||
if (this.tooltip == null) {
|
||||
this.tooltip = Platform.getTooltip(this.asItemStackRepresentation());
|
||||
}
|
||||
return this.tooltip;
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
public String getDisplayName()
|
||||
{
|
||||
if( this.displayName == null )
|
||||
{
|
||||
this.displayName = Platform.getItemDisplayName( this.asItemStackRepresentation() );
|
||||
}
|
||||
return this.displayName;
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getDisplayName() {
|
||||
if (this.displayName == null) {
|
||||
this.displayName = Platform.getItemDisplayName(this.asItemStackRepresentation());
|
||||
}
|
||||
return this.displayName;
|
||||
}
|
||||
|
||||
@SideOnly( Side.CLIENT )
|
||||
public String getModID()
|
||||
{
|
||||
return this.getDefinition().getItem().getRegistryName().getResourceDomain();
|
||||
}
|
||||
@SideOnly(Side.CLIENT)
|
||||
public String getModID() {
|
||||
return this.getDefinition().getItem().getRegistryName().getResourceDomain();
|
||||
}
|
||||
|
||||
public Optional<OreReference> getOre()
|
||||
{
|
||||
return this.oreReference;
|
||||
}
|
||||
public Optional<OreReference> getOre() {
|
||||
return this.oreReference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTagCompound()
|
||||
{
|
||||
return this.getDefinition().hasTagCompound();
|
||||
}
|
||||
@Override
|
||||
public boolean hasTagCompound() {
|
||||
return this.getDefinition().hasTagCompound();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack asItemStackRepresentation()
|
||||
{
|
||||
return this.getDefinition().copy();
|
||||
}
|
||||
@Override
|
||||
public ItemStack asItemStackRepresentation() {
|
||||
return this.getDefinition().copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getDefinition()
|
||||
{
|
||||
return this.sharedStack.getDefinition();
|
||||
}
|
||||
@Override
|
||||
public ItemStack getDefinition() {
|
||||
return this.sharedStack.getDefinition();
|
||||
}
|
||||
|
||||
AESharedItemStack getSharedStack()
|
||||
{
|
||||
return this.sharedStack;
|
||||
}
|
||||
AESharedItemStack getSharedStack() {
|
||||
return this.sharedStack;
|
||||
}
|
||||
|
||||
private boolean fuzzyItemStackComparison( ItemStack a, ItemStack b, FuzzyMode mode )
|
||||
{
|
||||
if( a.getItem() == b.getItem() && ( a.getItem().isDamageable() || Platform.isGTDamageableItem( a.getItem() ) ) )
|
||||
{
|
||||
if( mode == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
if( a.getItem().isDamageable() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if( Platform.isGTDamageableItem( a.getItem() ) )
|
||||
{
|
||||
return a.getItemDamage() == b.getItemDamage();
|
||||
}
|
||||
}
|
||||
else if( mode == FuzzyMode.PERCENT_99 )
|
||||
{
|
||||
if( Platform.isIC2DamageableItem( a.getItem() ) )
|
||||
{
|
||||
return ( (ICustomDamageItem) a.getItem() ).getCustomDamage( a ) > 1 == ( (ICustomDamageItem) b.getItem() ).getCustomDamage( b ) > 1;
|
||||
}
|
||||
else if( a.getItem().isDamageable() )
|
||||
{
|
||||
return a.getItemDamage() > 1 == b.getItemDamage() > 1;
|
||||
}
|
||||
else if( Platform.isGTDamageableItem( a.getItem() ) )
|
||||
{
|
||||
return ( (IToolItem) a.getItem() ).getItemDamage( a ) > 1 == ( (IToolItem) b.getItem() ).getItemDamage( b ) > 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
float percentDamageOfA = 0;
|
||||
float percentDamageOfB = 0;
|
||||
if( Platform.isIC2DamageableItem( a.getItem() ) )
|
||||
{
|
||||
percentDamageOfA = (float) ( (ICustomDamageItem) a.getItem() ).getCustomDamage( a ) / ( (ICustomDamageItem) a.getItem() ).getMaxCustomDamage( a );
|
||||
percentDamageOfB = (float) ( (ICustomDamageItem) b.getItem() ).getCustomDamage( b ) / ( (ICustomDamageItem) b.getItem() ).getMaxCustomDamage( b );
|
||||
}
|
||||
else if( a.getItem().isDamageable() )
|
||||
{
|
||||
percentDamageOfA = (float) a.getItemDamage() / a.getMaxDamage();
|
||||
percentDamageOfB = (float) b.getItemDamage() / b.getMaxDamage();
|
||||
}
|
||||
else if( Platform.isGTDamageableItem( a.getItem() ) )
|
||||
{
|
||||
percentDamageOfA = (float) ( (IToolItem) a.getItem() ).getItemDamage( a ) / ( (IToolItem) a.getItem() ).getMaxItemDamage( a );
|
||||
percentDamageOfB = (float) ( (IToolItem) b.getItem() ).getItemDamage( b ) / ( (IToolItem) b.getItem() ).getMaxItemDamage( b );
|
||||
}
|
||||
private boolean fuzzyItemStackComparison(ItemStack a, ItemStack b, FuzzyMode mode) {
|
||||
if (a.getItem() == b.getItem() && (a.getItem().isDamageable() || Platform.isGTDamageableItem(a.getItem()))) {
|
||||
if (mode == FuzzyMode.IGNORE_ALL) {
|
||||
if (a.getItem().isDamageable()) {
|
||||
return true;
|
||||
} else if (Platform.isGTDamageableItem(a.getItem())) {
|
||||
return a.getItemDamage() == b.getItemDamage();
|
||||
}
|
||||
} else if (mode == FuzzyMode.PERCENT_99) {
|
||||
if (Platform.isIC2DamageableItem(a.getItem())) {
|
||||
return ((ICustomDamageItem) a.getItem()).getCustomDamage(a) > 1 == ((ICustomDamageItem) b.getItem()).getCustomDamage(b) > 1;
|
||||
} else if (a.getItem().isDamageable()) {
|
||||
return a.getItemDamage() > 1 == b.getItemDamage() > 1;
|
||||
} else if (Platform.isGTDamageableItem(a.getItem())) {
|
||||
return ((IToolItem) a.getItem()).getItemDamage(a) > 1 == ((IToolItem) b.getItem()).getItemDamage(b) > 1;
|
||||
}
|
||||
} else {
|
||||
float percentDamageOfA = 0;
|
||||
float percentDamageOfB = 0;
|
||||
if (Platform.isIC2DamageableItem(a.getItem())) {
|
||||
percentDamageOfA = (float) ((ICustomDamageItem) a.getItem()).getCustomDamage(a) / ((ICustomDamageItem) a.getItem()).getMaxCustomDamage(a);
|
||||
percentDamageOfB = (float) ((ICustomDamageItem) b.getItem()).getCustomDamage(b) / ((ICustomDamageItem) b.getItem()).getMaxCustomDamage(b);
|
||||
} else if (a.getItem().isDamageable()) {
|
||||
percentDamageOfA = (float) a.getItemDamage() / a.getMaxDamage();
|
||||
percentDamageOfB = (float) b.getItemDamage() / b.getMaxDamage();
|
||||
} else if (Platform.isGTDamageableItem(a.getItem())) {
|
||||
percentDamageOfA = (float) ((IToolItem) a.getItem()).getItemDamage(a) / ((IToolItem) a.getItem()).getMaxItemDamage(a);
|
||||
percentDamageOfB = (float) ((IToolItem) b.getItem()).getItemDamage(b) / ((IToolItem) b.getItem()).getMaxItemDamage(b);
|
||||
}
|
||||
|
||||
return percentDamageOfA > mode.breakPoint == percentDamageOfB > mode.breakPoint;
|
||||
}
|
||||
}
|
||||
return percentDamageOfA > mode.breakPoint == percentDamageOfB > mode.breakPoint;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,12 +23,11 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.WeakHashMap;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public final class AEItemStackRegistry {
|
||||
private static final WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> REGISTRY = new WeakHashMap<>();
|
||||
|
||||
@@ -18,82 +18,70 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
final class AESharedItemStack
|
||||
{
|
||||
|
||||
private final ItemStack itemStack;
|
||||
private final int itemDamage;
|
||||
private final int hashCode;
|
||||
final class AESharedItemStack {
|
||||
|
||||
public AESharedItemStack( final ItemStack itemStack )
|
||||
{
|
||||
this( itemStack, itemStack.getItemDamage() );
|
||||
}
|
||||
private final ItemStack itemStack;
|
||||
private final int itemDamage;
|
||||
private final int hashCode;
|
||||
|
||||
/**
|
||||
* A constructor to explicitly set the damage value and not fetch it from the {@link ItemStack}
|
||||
*
|
||||
* @param itemStack The {@link ItemStack} to filter
|
||||
* @param damage The damage of the item
|
||||
*/
|
||||
private AESharedItemStack( ItemStack itemStack, int damage )
|
||||
{
|
||||
this.itemStack = itemStack;
|
||||
this.itemDamage = damage;
|
||||
public AESharedItemStack(final ItemStack itemStack) {
|
||||
this(itemStack, itemStack.getItemDamage());
|
||||
}
|
||||
|
||||
// Ensure this is always called last.
|
||||
this.hashCode = this.makeHashCode();
|
||||
}
|
||||
/**
|
||||
* A constructor to explicitly set the damage value and not fetch it from the {@link ItemStack}
|
||||
*
|
||||
* @param itemStack The {@link ItemStack} to filter
|
||||
* @param damage The damage of the item
|
||||
*/
|
||||
private AESharedItemStack(ItemStack itemStack, int damage) {
|
||||
this.itemStack = itemStack;
|
||||
this.itemDamage = damage;
|
||||
|
||||
ItemStack getDefinition()
|
||||
{
|
||||
return this.itemStack;
|
||||
}
|
||||
// Ensure this is always called last.
|
||||
this.hashCode = this.makeHashCode();
|
||||
}
|
||||
|
||||
int getItemDamage()
|
||||
{
|
||||
return this.itemDamage;
|
||||
}
|
||||
ItemStack getDefinition() {
|
||||
return this.itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return this.hashCode;
|
||||
}
|
||||
int getItemDamage() {
|
||||
return this.itemDamage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( final Object obj )
|
||||
{
|
||||
if( this == obj )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if( !( obj instanceof AESharedItemStack ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.hashCode;
|
||||
}
|
||||
|
||||
final AESharedItemStack other = (AESharedItemStack) obj;
|
||||
Preconditions.checkState( this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1" );
|
||||
Preconditions.checkArgument( other.getDefinition().getCount() == 1, "ItemStack#getCount() has to be 1" );
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof AESharedItemStack)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( this.itemStack == other.itemStack )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return ItemStack.areItemStacksEqual( this.itemStack, other.itemStack );
|
||||
}
|
||||
final AESharedItemStack other = (AESharedItemStack) obj;
|
||||
Preconditions.checkState(this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1");
|
||||
Preconditions.checkArgument(other.getDefinition().getCount() == 1, "ItemStack#getCount() has to be 1");
|
||||
|
||||
private int makeHashCode()
|
||||
{
|
||||
return Objects.hash( this.itemStack.getItem(), this.itemDamage, this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound() : 0 );
|
||||
}
|
||||
if (this.itemStack == other.itemStack) {
|
||||
return true;
|
||||
}
|
||||
return ItemStack.areItemStacksEqual(this.itemStack, other.itemStack);
|
||||
}
|
||||
|
||||
private int makeHashCode() {
|
||||
return Objects.hash(this.itemStack.getItem(), this.itemDamage, this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound() : 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,22 +28,16 @@ public abstract class AEStack<T extends IAEStack<T>> implements IAEStack<T> {
|
||||
private long stackSize;
|
||||
private long countRequestable;
|
||||
|
||||
protected static long getPacketValue( final byte type, final ByteBuf tag )
|
||||
{
|
||||
if( type == 0 )
|
||||
{
|
||||
protected static long getPacketValue(final byte type, final ByteBuf tag) {
|
||||
if (type == 0) {
|
||||
long l = tag.readByte();
|
||||
l -= Byte.MIN_VALUE;
|
||||
return l;
|
||||
}
|
||||
else if( type == 1 )
|
||||
{
|
||||
} else if (type == 1) {
|
||||
long l = tag.readShort();
|
||||
l -= Short.MIN_VALUE;
|
||||
return l;
|
||||
}
|
||||
else if( type == 2 )
|
||||
{
|
||||
} else if (type == 2) {
|
||||
long l = tag.readInt();
|
||||
l -= Integer.MIN_VALUE;
|
||||
return l;
|
||||
@@ -125,45 +119,29 @@ public abstract class AEStack<T extends IAEStack<T>> implements IAEStack<T> {
|
||||
this.countRequestable -= i;
|
||||
}
|
||||
|
||||
protected byte getType( final long num )
|
||||
{
|
||||
if( num <= 255 )
|
||||
{
|
||||
protected byte getType(final long num) {
|
||||
if (num <= 255) {
|
||||
return 0;
|
||||
}
|
||||
else if( num <= 65535 )
|
||||
{
|
||||
} else if (num <= 65535) {
|
||||
return 1;
|
||||
}
|
||||
else if( num <= 4294967295L )
|
||||
{
|
||||
} else if (num <= 4294967295L) {
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract boolean hasTagCompound();
|
||||
|
||||
protected void putPacketValue( final ByteBuf tag, final long num )
|
||||
{
|
||||
if( num <= 255 )
|
||||
{
|
||||
tag.writeByte( (byte) ( num + Byte.MIN_VALUE ) );
|
||||
}
|
||||
else if( num <= 65535 )
|
||||
{
|
||||
tag.writeShort( (short) ( num + Short.MIN_VALUE ) );
|
||||
}
|
||||
else if( num <= 4294967295L )
|
||||
{
|
||||
tag.writeInt( (int) ( num + Integer.MIN_VALUE ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
tag.writeLong( num );
|
||||
protected void putPacketValue(final ByteBuf tag, final long num) {
|
||||
if (num <= 255) {
|
||||
tag.writeByte((byte) (num + Byte.MIN_VALUE));
|
||||
} else if (num <= 65535) {
|
||||
tag.writeShort((short) (num + Short.MIN_VALUE));
|
||||
} else if (num <= 4294967295L) {
|
||||
tag.writeInt((int) (num + Integer.MIN_VALUE));
|
||||
} else {
|
||||
tag.writeLong(num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,227 +18,189 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.Platform;
|
||||
import com.google.common.base.Preconditions;
|
||||
import gregtech.api.items.IToolItem;
|
||||
import ic2.api.item.ICustomDamageItem;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectAVLTreeMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectSortedMap;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
|
||||
import appeng.util.Platform;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import gregtech.api.items.IToolItem;
|
||||
import ic2.api.item.ICustomDamageItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectAVLTreeMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectSortedMap;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
|
||||
/**
|
||||
* This variant list is optimized for damageable items, and supports selecting durability ranges with
|
||||
* {@link #findFuzzy(IAEItemStack, FuzzyMode)}.
|
||||
*/
|
||||
class FuzzyItemVariantList extends ItemVariantList
|
||||
{
|
||||
class FuzzyItemVariantList extends ItemVariantList {
|
||||
|
||||
static final SharedStackComparator COMPARATOR = new SharedStackComparator();
|
||||
static final SharedStackComparator COMPARATOR = new SharedStackComparator();
|
||||
|
||||
// NOTE: We only use Object as they key here so we can pass our special DamageBounds to the subMap method.
|
||||
// We NEVER put any keys in this map that are not AESharedItemStacks.
|
||||
private final Object2ObjectSortedMap<Object, IAEItemStack> records = new Object2ObjectAVLTreeMap<>( COMPARATOR );
|
||||
// NOTE: We only use Object as they key here so we can pass our special DamageBounds to the subMap method.
|
||||
// We NEVER put any keys in this map that are not AESharedItemStacks.
|
||||
private final Object2ObjectSortedMap<Object, IAEItemStack> records = new Object2ObjectAVLTreeMap<>(COMPARATOR);
|
||||
|
||||
@Override
|
||||
public Collection<IAEItemStack> findFuzzy( final IAEItemStack filter, final FuzzyMode fuzzy )
|
||||
{
|
||||
ItemStack itemStack = filter.getDefinition();
|
||||
@Override
|
||||
public Collection<IAEItemStack> findFuzzy(final IAEItemStack filter, final FuzzyMode fuzzy) {
|
||||
ItemStack itemStack = filter.getDefinition();
|
||||
|
||||
ItemDamageBound lowerBound = makeLowerBound( itemStack, fuzzy );
|
||||
ItemDamageBound upperBound = makeUpperBound( itemStack, fuzzy );
|
||||
Preconditions.checkState( lowerBound.itemDamage > upperBound.itemDamage );
|
||||
ItemDamageBound lowerBound = makeLowerBound(itemStack, fuzzy);
|
||||
ItemDamageBound upperBound = makeUpperBound(itemStack, fuzzy);
|
||||
Preconditions.checkState(lowerBound.itemDamage > upperBound.itemDamage);
|
||||
|
||||
return this.records.subMap( lowerBound, upperBound ).values();
|
||||
}
|
||||
return this.records.subMap(lowerBound, upperBound).values();
|
||||
}
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
@Override
|
||||
Map<AESharedItemStack, IAEItemStack> getRecords()
|
||||
{
|
||||
// We ensure on our end that we NEVER use anything but AESharedItemStack as the key in this map
|
||||
return (Map<AESharedItemStack, IAEItemStack>) (Object) this.records;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
Map<AESharedItemStack, IAEItemStack> getRecords() {
|
||||
// We ensure on our end that we NEVER use anything but AESharedItemStack as the key in this map
|
||||
return (Map<AESharedItemStack, IAEItemStack>) (Object) this.records;
|
||||
}
|
||||
|
||||
static class ItemDamageBound
|
||||
{
|
||||
final int itemDamage;
|
||||
static class ItemDamageBound {
|
||||
final int itemDamage;
|
||||
|
||||
public ItemDamageBound( int itemDamage )
|
||||
{
|
||||
this.itemDamage = itemDamage;
|
||||
}
|
||||
}
|
||||
public ItemDamageBound(int itemDamage) {
|
||||
this.itemDamage = itemDamage;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This comparator creates a strict and total ordering over all {@link AESharedItemStack} of the same item. To
|
||||
* support selecting ranges of durability, it is defined for type {@link Object} and also accepts
|
||||
* {@link ItemDamageBound} as an argument to compare against.
|
||||
*/
|
||||
static class SharedStackComparator implements Comparator<Object>
|
||||
{
|
||||
@Override
|
||||
public int compare( Object a, Object b )
|
||||
{
|
||||
// Either argument can either be a damage bound or a shared item stack
|
||||
// Since we never put damage bounds into the map as keys, only one
|
||||
// of the two arguments can possibly be a bound
|
||||
ItemDamageBound boundA = null;
|
||||
AESharedItemStack stackA = null;
|
||||
int itemDamageA;
|
||||
if( a instanceof ItemDamageBound )
|
||||
{
|
||||
boundA = (ItemDamageBound) a;
|
||||
itemDamageA = boundA.itemDamage;
|
||||
}
|
||||
else
|
||||
{
|
||||
stackA = (AESharedItemStack) a;
|
||||
itemDamageA = stackA.getItemDamage();
|
||||
}
|
||||
ItemDamageBound boundB = null;
|
||||
AESharedItemStack stackB = null;
|
||||
int itemDamageB;
|
||||
if( b instanceof ItemDamageBound )
|
||||
{
|
||||
boundB = (ItemDamageBound) b;
|
||||
itemDamageB = boundB.itemDamage;
|
||||
}
|
||||
else
|
||||
{
|
||||
stackB = (AESharedItemStack) b;
|
||||
itemDamageB = stackB.getItemDamage();
|
||||
}
|
||||
/**
|
||||
* This comparator creates a strict and total ordering over all {@link AESharedItemStack} of the same item. To
|
||||
* support selecting ranges of durability, it is defined for type {@link Object} and also accepts
|
||||
* {@link ItemDamageBound} as an argument to compare against.
|
||||
*/
|
||||
static class SharedStackComparator implements Comparator<Object> {
|
||||
@Override
|
||||
public int compare(Object a, Object b) {
|
||||
// Either argument can either be a damage bound or a shared item stack
|
||||
// Since we never put damage bounds into the map as keys, only one
|
||||
// of the two arguments can possibly be a bound
|
||||
ItemDamageBound boundA = null;
|
||||
AESharedItemStack stackA = null;
|
||||
int itemDamageA;
|
||||
if (a instanceof ItemDamageBound) {
|
||||
boundA = (ItemDamageBound) a;
|
||||
itemDamageA = boundA.itemDamage;
|
||||
} else {
|
||||
stackA = (AESharedItemStack) a;
|
||||
itemDamageA = stackA.getItemDamage();
|
||||
}
|
||||
ItemDamageBound boundB = null;
|
||||
AESharedItemStack stackB = null;
|
||||
int itemDamageB;
|
||||
if (b instanceof ItemDamageBound) {
|
||||
boundB = (ItemDamageBound) b;
|
||||
itemDamageB = boundB.itemDamage;
|
||||
} else {
|
||||
stackB = (AESharedItemStack) b;
|
||||
itemDamageB = stackB.getItemDamage();
|
||||
}
|
||||
|
||||
// When either argument is a damage bound, we just compare the damage values because it is used
|
||||
// only to get a certain damage range out of the map.
|
||||
if( boundA != null || boundB != null )
|
||||
{
|
||||
return Integer.compare( itemDamageB, itemDamageA );
|
||||
}
|
||||
// When either argument is a damage bound, we just compare the damage values because it is used
|
||||
// only to get a certain damage range out of the map.
|
||||
if (boundA != null || boundB != null) {
|
||||
return Integer.compare(itemDamageB, itemDamageA);
|
||||
}
|
||||
|
||||
ItemStack itemStackA = stackA.getDefinition();
|
||||
ItemStack itemStackB = stackB.getDefinition();
|
||||
Preconditions.checkState( itemStackA.getCount() == 1, "ItemStack#getCount() has to be 1" );
|
||||
Preconditions.checkArgument( itemStackB.getCount() == 1, "ItemStack#getCount() has to be 1" );
|
||||
ItemStack itemStackA = stackA.getDefinition();
|
||||
ItemStack itemStackB = stackB.getDefinition();
|
||||
Preconditions.checkState(itemStackA.getCount() == 1, "ItemStack#getCount() has to be 1");
|
||||
Preconditions.checkArgument(itemStackB.getCount() == 1, "ItemStack#getCount() has to be 1");
|
||||
|
||||
if( itemStackA == itemStackB )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (itemStackA == itemStackB) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Damaged items are sorted before undamaged items
|
||||
final int damageValue = Integer.compare( itemDamageB, itemDamageA );
|
||||
if( damageValue != 0 )
|
||||
{
|
||||
return damageValue;
|
||||
}
|
||||
// Damaged items are sorted before undamaged items
|
||||
final int damageValue = Integer.compare(itemDamageB, itemDamageA);
|
||||
if (damageValue != 0) {
|
||||
return damageValue;
|
||||
}
|
||||
|
||||
// As a final tie breaker, order by the object identity of the item stack
|
||||
// While this will order seemingly at random, we only need the order of
|
||||
// damage values to be predictable, while still having to satisfy the
|
||||
// complete order requirements of the sorted map
|
||||
return Long.compare( System.identityHashCode( itemStackA ), System.identityHashCode( itemStackB ) );
|
||||
}
|
||||
}
|
||||
// As a final tie breaker, order by the object identity of the item stack
|
||||
// While this will order seemingly at random, we only need the order of
|
||||
// damage values to be predictable, while still having to satisfy the
|
||||
// complete order requirements of the sorted map
|
||||
return Long.compare(System.identityHashCode(itemStackA), System.identityHashCode(itemStackB));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Minecraft reverses the damage values. So anything with a damage of 0 is undamaged and increases the more damaged
|
||||
* the item is.
|
||||
* <p>
|
||||
* Further the used subMap follows [MAX_DAMAGE, MIN_DAMAGE), so to include undamaged items, we have to start with a
|
||||
* lower damage value than 0, while it is fine to use {@link ItemStack#getMaxDamage()} for the upper bound.
|
||||
*/
|
||||
private static final int MIN_DAMAGE_VALUE = -1;
|
||||
/**
|
||||
* Minecraft reverses the damage values. So anything with a damage of 0 is undamaged and increases the more damaged
|
||||
* the item is.
|
||||
* <p>
|
||||
* Further the used subMap follows [MAX_DAMAGE, MIN_DAMAGE), so to include undamaged items, we have to start with a
|
||||
* lower damage value than 0, while it is fine to use {@link ItemStack#getMaxDamage()} for the upper bound.
|
||||
*/
|
||||
private static final int MIN_DAMAGE_VALUE = -1;
|
||||
|
||||
/*
|
||||
* Keep in mind that the stack order is from most damaged to least damaged, so this lower bound will actually be a
|
||||
* higher number than the upper bound.
|
||||
*/
|
||||
static ItemDamageBound makeLowerBound( final ItemStack stack, final FuzzyMode fuzzy )
|
||||
{
|
||||
Preconditions.checkState( stack.getItem().isDamageable() || ( Platform.isGTDamageableItem( stack.getItem() ) ), "Item#isDamageable() has to be true" );
|
||||
/*
|
||||
* Keep in mind that the stack order is from most damaged to least damaged, so this lower bound will actually be a
|
||||
* higher number than the upper bound.
|
||||
*/
|
||||
static ItemDamageBound makeLowerBound(final ItemStack stack, final FuzzyMode fuzzy) {
|
||||
Preconditions.checkState(stack.getItem().isDamageable() || (Platform.isGTDamageableItem(stack.getItem())), "Item#isDamageable() has to be true");
|
||||
|
||||
int damage;
|
||||
int maxDamage;
|
||||
if( Platform.isIC2DamageableItem( stack.getItem() ) )
|
||||
{
|
||||
maxDamage = ( (ICustomDamageItem) stack.getItem() ).getMaxCustomDamage( stack );
|
||||
damage = ( (ICustomDamageItem) stack.getItem() ).getCustomDamage( stack );
|
||||
}
|
||||
else if( Platform.isGTDamageableItem( stack.getItem() ) )
|
||||
{
|
||||
maxDamage = ( (IToolItem) stack.getItem() ).getMaxItemDamage( stack );
|
||||
damage = ( (IToolItem) stack.getItem() ).getItemDamage( stack );
|
||||
}
|
||||
else
|
||||
{
|
||||
maxDamage = stack.getMaxDamage();
|
||||
damage = stack.getItemDamage();
|
||||
}
|
||||
int damage;
|
||||
int maxDamage;
|
||||
if (Platform.isIC2DamageableItem(stack.getItem())) {
|
||||
maxDamage = ((ICustomDamageItem) stack.getItem()).getMaxCustomDamage(stack);
|
||||
damage = ((ICustomDamageItem) stack.getItem()).getCustomDamage(stack);
|
||||
} else if (Platform.isGTDamageableItem(stack.getItem())) {
|
||||
maxDamage = ((IToolItem) stack.getItem()).getMaxItemDamage(stack);
|
||||
damage = ((IToolItem) stack.getItem()).getItemDamage(stack);
|
||||
} else {
|
||||
maxDamage = stack.getMaxDamage();
|
||||
damage = stack.getItemDamage();
|
||||
}
|
||||
|
||||
if( fuzzy == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
if( maxDamage != 0 )
|
||||
{
|
||||
damage = maxDamage;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final int breakpoint = fuzzy.calculateBreakPoint( maxDamage );
|
||||
damage = damage <= breakpoint ? breakpoint : maxDamage;
|
||||
}
|
||||
if (fuzzy == FuzzyMode.IGNORE_ALL) {
|
||||
if (maxDamage != 0) {
|
||||
damage = maxDamage;
|
||||
}
|
||||
} else {
|
||||
final int breakpoint = fuzzy.calculateBreakPoint(maxDamage);
|
||||
damage = damage <= breakpoint ? breakpoint : maxDamage;
|
||||
}
|
||||
|
||||
return new ItemDamageBound( damage );
|
||||
}
|
||||
return new ItemDamageBound(damage);
|
||||
}
|
||||
|
||||
/*
|
||||
* Keep in mind that the stack order is from most damaged to least damaged, so this upper bound will actually be a
|
||||
* lower number than the lower bound. It also is exclusive.
|
||||
*/
|
||||
static ItemDamageBound makeUpperBound( final ItemStack stack, final FuzzyMode fuzzy )
|
||||
{
|
||||
Preconditions.checkState( stack.getItem().isDamageable() || ( Platform.isGTDamageableItem( stack.getItem() ) ), "Item#isDamageable() has to be true" );
|
||||
/*
|
||||
* Keep in mind that the stack order is from most damaged to least damaged, so this upper bound will actually be a
|
||||
* lower number than the lower bound. It also is exclusive.
|
||||
*/
|
||||
static ItemDamageBound makeUpperBound(final ItemStack stack, final FuzzyMode fuzzy) {
|
||||
Preconditions.checkState(stack.getItem().isDamageable() || (Platform.isGTDamageableItem(stack.getItem())), "Item#isDamageable() has to be true");
|
||||
|
||||
int damage;
|
||||
if( fuzzy == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
damage = MIN_DAMAGE_VALUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
int maxDamage;
|
||||
if( Platform.isIC2DamageableItem( stack.getItem() ) )
|
||||
{
|
||||
maxDamage = ( (ICustomDamageItem) stack.getItem() ).getMaxCustomDamage( stack );
|
||||
damage = ( (ICustomDamageItem) stack.getItem() ).getCustomDamage( stack );
|
||||
}
|
||||
else if( Platform.isGTDamageableItem( stack.getItem() ) )
|
||||
{
|
||||
maxDamage = ( (IToolItem) stack.getItem() ).getMaxItemDamage( stack );
|
||||
damage = ( (IToolItem) stack.getItem() ).getItemDamage( stack );
|
||||
}
|
||||
else
|
||||
{
|
||||
maxDamage = stack.getMaxDamage();
|
||||
damage = stack.getItemDamage();
|
||||
}
|
||||
int damage;
|
||||
if (fuzzy == FuzzyMode.IGNORE_ALL) {
|
||||
damage = MIN_DAMAGE_VALUE;
|
||||
} else {
|
||||
int maxDamage;
|
||||
if (Platform.isIC2DamageableItem(stack.getItem())) {
|
||||
maxDamage = ((ICustomDamageItem) stack.getItem()).getMaxCustomDamage(stack);
|
||||
damage = ((ICustomDamageItem) stack.getItem()).getCustomDamage(stack);
|
||||
} else if (Platform.isGTDamageableItem(stack.getItem())) {
|
||||
maxDamage = ((IToolItem) stack.getItem()).getMaxItemDamage(stack);
|
||||
damage = ((IToolItem) stack.getItem()).getItemDamage(stack);
|
||||
} else {
|
||||
maxDamage = stack.getMaxDamage();
|
||||
damage = stack.getItemDamage();
|
||||
}
|
||||
|
||||
final int breakpoint = fuzzy.calculateBreakPoint( maxDamage );
|
||||
damage = damage <= breakpoint ? MIN_DAMAGE_VALUE : breakpoint;
|
||||
}
|
||||
final int breakpoint = fuzzy.calculateBreakPoint(maxDamage);
|
||||
damage = damage <= breakpoint ? MIN_DAMAGE_VALUE : breakpoint;
|
||||
}
|
||||
|
||||
return new ItemDamageBound( damage );
|
||||
}
|
||||
return new ItemDamageBound(damage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,234 +18,192 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.util.Platform;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
||||
public final class ItemList implements IItemList<IAEItemStack>
|
||||
{
|
||||
public final class ItemList implements IItemList<IAEItemStack> {
|
||||
|
||||
private final Reference2ObjectMap<Item, ItemVariantList> records = new Reference2ObjectOpenHashMap<>();
|
||||
/**
|
||||
* We increment this version field everytime an attempt to mutate this item list (or potentially one of its
|
||||
* sub-lists) is made. Iterators will copy the version when they are created and compare it against the current
|
||||
* version whenever they advance to trigger a {@link ConcurrentModificationException}.
|
||||
*/
|
||||
private final AtomicInteger version = new AtomicInteger( 0 );
|
||||
private final Reference2ObjectMap<Item, ItemVariantList> records = new Reference2ObjectOpenHashMap<>();
|
||||
/**
|
||||
* We increment this version field everytime an attempt to mutate this item list (or potentially one of its
|
||||
* sub-lists) is made. Iterators will copy the version when they are created and compare it against the current
|
||||
* version whenever they advance to trigger a {@link ConcurrentModificationException}.
|
||||
*/
|
||||
private final AtomicInteger version = new AtomicInteger(0);
|
||||
|
||||
@Override
|
||||
public IAEItemStack findPrecise( final IAEItemStack itemStack )
|
||||
{
|
||||
if( itemStack == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack findPrecise(final IAEItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ItemVariantList record = this.records.get( itemStack.getItem() );
|
||||
return record != null ? record.findPrecise( itemStack ) : null;
|
||||
}
|
||||
ItemVariantList record = this.records.get(itemStack.getItem());
|
||||
return record != null ? record.findPrecise(itemStack) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IAEItemStack> findFuzzy( final IAEItemStack filter, final FuzzyMode fuzzy )
|
||||
{
|
||||
if( filter == null )
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@Override
|
||||
public Collection<IAEItemStack> findFuzzy(final IAEItemStack filter, final FuzzyMode fuzzy) {
|
||||
if (filter == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
ItemVariantList record = this.records.get( filter.getItem() );
|
||||
return record != null ? record.findFuzzy( filter, fuzzy ) : Collections.emptyList();
|
||||
}
|
||||
ItemVariantList record = this.records.get(filter.getItem());
|
||||
return record != null ? record.findFuzzy(filter, fuzzy) : Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add( final IAEItemStack itemStack )
|
||||
{
|
||||
version.incrementAndGet();
|
||||
@Override
|
||||
public void add(final IAEItemStack itemStack) {
|
||||
version.incrementAndGet();
|
||||
|
||||
if( itemStack == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.getOrCreateRecord( itemStack.getItem() ).add( itemStack );
|
||||
}
|
||||
this.getOrCreateRecord(itemStack.getItem()).add(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStorage( final IAEItemStack itemStack )
|
||||
{
|
||||
version.incrementAndGet();
|
||||
@Override
|
||||
public void addStorage(final IAEItemStack itemStack) {
|
||||
version.incrementAndGet();
|
||||
|
||||
if( itemStack == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.getOrCreateRecord( itemStack.getItem() ).addStorage( itemStack );
|
||||
}
|
||||
this.getOrCreateRecord(itemStack.getItem()).addStorage(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCrafting( final IAEItemStack itemStack )
|
||||
{
|
||||
version.incrementAndGet();
|
||||
@Override
|
||||
public void addCrafting(final IAEItemStack itemStack) {
|
||||
version.incrementAndGet();
|
||||
|
||||
if( itemStack == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.getOrCreateRecord( itemStack.getItem() ).addCrafting( itemStack );
|
||||
}
|
||||
this.getOrCreateRecord(itemStack.getItem()).addCrafting(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequestable( final IAEItemStack itemStack )
|
||||
{
|
||||
version.incrementAndGet();
|
||||
@Override
|
||||
public void addRequestable(final IAEItemStack itemStack) {
|
||||
version.incrementAndGet();
|
||||
|
||||
if( itemStack == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.getOrCreateRecord( itemStack.getItem() ).addRequestable( itemStack );
|
||||
}
|
||||
this.getOrCreateRecord(itemStack.getItem()).addRequestable(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack getFirstItem()
|
||||
{
|
||||
for( final IAEItemStack stackType : this )
|
||||
{
|
||||
return stackType;
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack getFirstItem() {
|
||||
for (final IAEItemStack stackType : this) {
|
||||
return stackType;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
int size = 0;
|
||||
for( ItemVariantList entry : records.values() )
|
||||
{
|
||||
size += entry.size();
|
||||
}
|
||||
@Override
|
||||
public int size() {
|
||||
int size = 0;
|
||||
for (ItemVariantList entry : records.values()) {
|
||||
size += entry.size();
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IAEItemStack> iterator()
|
||||
{
|
||||
return new ChainedIterator( this.records.values().iterator(), version );
|
||||
}
|
||||
@Override
|
||||
public Iterator<IAEItemStack> iterator() {
|
||||
return new ChainedIterator(this.records.values().iterator(), version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetStatus()
|
||||
{
|
||||
for( final IAEItemStack i : this )
|
||||
{
|
||||
i.reset();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void resetStatus() {
|
||||
for (final IAEItemStack i : this) {
|
||||
i.reset();
|
||||
}
|
||||
}
|
||||
|
||||
private ItemVariantList getOrCreateRecord( Item item )
|
||||
{
|
||||
return this.records.computeIfAbsent( item, this::makeRecordMap );
|
||||
}
|
||||
private ItemVariantList getOrCreateRecord(Item item) {
|
||||
return this.records.computeIfAbsent(item, this::makeRecordMap);
|
||||
}
|
||||
|
||||
private ItemVariantList makeRecordMap( Item item )
|
||||
{
|
||||
if( item.isDamageable() || Platform.isGTDamageableItem( item ) )
|
||||
{
|
||||
return new FuzzyItemVariantList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new NormalItemVariantList();
|
||||
}
|
||||
}
|
||||
private ItemVariantList makeRecordMap(Item item) {
|
||||
if (item.isDamageable() || Platform.isGTDamageableItem(item)) {
|
||||
return new FuzzyItemVariantList();
|
||||
} else {
|
||||
return new NormalItemVariantList();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates over multiple item lists as if they were one list.
|
||||
*/
|
||||
private static class ChainedIterator implements Iterator<IAEItemStack>
|
||||
{
|
||||
/**
|
||||
* Iterates over multiple item lists as if they were one list.
|
||||
*/
|
||||
private static class ChainedIterator implements Iterator<IAEItemStack> {
|
||||
|
||||
private final AtomicInteger parentVersion;
|
||||
private final int version;
|
||||
private final Iterator<ItemVariantList> parent;
|
||||
private Iterator<IAEItemStack> next;
|
||||
private final AtomicInteger parentVersion;
|
||||
private final int version;
|
||||
private final Iterator<ItemVariantList> parent;
|
||||
private Iterator<IAEItemStack> next;
|
||||
|
||||
public ChainedIterator( Iterator<ItemVariantList> iterator, AtomicInteger parentVersion )
|
||||
{
|
||||
this.parent = iterator;
|
||||
this.parentVersion = parentVersion;
|
||||
this.version = parentVersion.get();
|
||||
this.ensureItems();
|
||||
}
|
||||
public ChainedIterator(Iterator<ItemVariantList> iterator, AtomicInteger parentVersion) {
|
||||
this.parent = iterator;
|
||||
this.parentVersion = parentVersion;
|
||||
this.version = parentVersion.get();
|
||||
this.ensureItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return next != null && next.hasNext();
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return next != null && next.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack next()
|
||||
{
|
||||
if( this.next == null )
|
||||
{
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
if( this.version != this.parentVersion.get() )
|
||||
{
|
||||
throw new ConcurrentModificationException();
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack next() {
|
||||
if (this.next == null) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
if (this.version != this.parentVersion.get()) {
|
||||
throw new ConcurrentModificationException();
|
||||
}
|
||||
|
||||
IAEItemStack result = this.next.next();
|
||||
this.ensureItems();
|
||||
return result;
|
||||
}
|
||||
IAEItemStack result = this.next.next();
|
||||
this.ensureItems();
|
||||
return result;
|
||||
}
|
||||
|
||||
private void ensureItems()
|
||||
{
|
||||
if( hasNext() )
|
||||
{
|
||||
return; // Still items left in the current one
|
||||
}
|
||||
private void ensureItems() {
|
||||
if (hasNext()) {
|
||||
return; // Still items left in the current one
|
||||
}
|
||||
|
||||
// Find the next iterator willing to return some items...
|
||||
while ( this.parent.hasNext() )
|
||||
{
|
||||
this.next = this.parent.next().iterator();
|
||||
// Find the next iterator willing to return some items...
|
||||
while (this.parent.hasNext()) {
|
||||
this.next = this.parent.next().iterator();
|
||||
|
||||
if( this.next.hasNext() )
|
||||
{
|
||||
return; // Found one!
|
||||
}
|
||||
}
|
||||
if (this.next.hasNext()) {
|
||||
return; // Found one!
|
||||
}
|
||||
}
|
||||
|
||||
// No more items
|
||||
this.next = null;
|
||||
}
|
||||
}
|
||||
// No more items
|
||||
this.next = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,69 +19,56 @@
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemContainer;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class ItemModList implements IItemContainer<IAEItemStack>
|
||||
{
|
||||
|
||||
private final IItemContainer<IAEItemStack> backingStore;
|
||||
private final IItemContainer<IAEItemStack> overrides = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
public class ItemModList implements IItemContainer<IAEItemStack> {
|
||||
|
||||
public ItemModList( final IItemContainer<IAEItemStack> backend )
|
||||
{
|
||||
this.backingStore = backend;
|
||||
}
|
||||
private final IItemContainer<IAEItemStack> backingStore;
|
||||
private final IItemContainer<IAEItemStack> overrides = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
|
||||
|
||||
@Override
|
||||
public void add( final IAEItemStack option )
|
||||
{
|
||||
IAEItemStack over = this.overrides.findPrecise( option );
|
||||
if( over == null )
|
||||
{
|
||||
over = this.backingStore.findPrecise( option );
|
||||
if( over == null )
|
||||
{
|
||||
this.overrides.add( option );
|
||||
}
|
||||
else
|
||||
{
|
||||
option.add( over );
|
||||
this.overrides.add( option );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.overrides.add( option );
|
||||
}
|
||||
}
|
||||
public ItemModList(final IItemContainer<IAEItemStack> backend) {
|
||||
this.backingStore = backend;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack findPrecise( final IAEItemStack i )
|
||||
{
|
||||
final IAEItemStack over = this.overrides.findPrecise( i );
|
||||
if( over == null )
|
||||
{
|
||||
return this.backingStore.findPrecise( i );
|
||||
}
|
||||
return over;
|
||||
}
|
||||
@Override
|
||||
public void add(final IAEItemStack option) {
|
||||
IAEItemStack over = this.overrides.findPrecise(option);
|
||||
if (over == null) {
|
||||
over = this.backingStore.findPrecise(option);
|
||||
if (over == null) {
|
||||
this.overrides.add(option);
|
||||
} else {
|
||||
option.add(over);
|
||||
this.overrides.add(option);
|
||||
}
|
||||
} else {
|
||||
this.overrides.add(option);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IAEItemStack> findFuzzy( final IAEItemStack input, final FuzzyMode fuzzy )
|
||||
{
|
||||
return this.overrides.findFuzzy( input, fuzzy );
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack findPrecise(final IAEItemStack i) {
|
||||
final IAEItemStack over = this.overrides.findPrecise(i);
|
||||
if (over == null) {
|
||||
return this.backingStore.findPrecise(i);
|
||||
}
|
||||
return over;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return this.overrides.isEmpty() && this.backingStore.isEmpty();
|
||||
}
|
||||
@Override
|
||||
public Collection<IAEItemStack> findFuzzy(final IAEItemStack input, final FuzzyMode fuzzy) {
|
||||
return this.overrides.findFuzzy(input, fuzzy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.overrides.isEmpty() && this.backingStore.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
/**
|
||||
* Stores variants of a single type of {@link net.minecraft.item.Item}, i.e. versions with different durability, or
|
||||
* different NBT or capabilities.
|
||||
|
||||
@@ -18,12 +18,12 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
/**
|
||||
* This iterator will only return items from a collection that are meaningful (w.r.t.
|
||||
* {@link IAEItemStack#isMeaningful()}. Items that are not meaningful are automatically removed from the collection as
|
||||
|
||||
@@ -18,14 +18,13 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This variant list is optimized for items that cannot be damaged and thus do not support querying durability ranges
|
||||
|
||||
@@ -8,8 +8,7 @@ import java.util.List;
|
||||
* @author brachy84
|
||||
* @butcherer PrototypeTrousers
|
||||
*/
|
||||
public class OreDictFilterMatcher
|
||||
{
|
||||
public class OreDictFilterMatcher {
|
||||
|
||||
/**
|
||||
* Parses the given expression and creates a List.
|
||||
@@ -17,10 +16,9 @@ public class OreDictFilterMatcher
|
||||
* @param expression expr to parse
|
||||
* @return match rule list
|
||||
*/
|
||||
public static List<MatchRule> parseExpression( String expression )
|
||||
{
|
||||
public static List<MatchRule> parseExpression(String expression) {
|
||||
List<MatchRule> rules = new ArrayList<>();
|
||||
parseExpression( rules, expression );
|
||||
parseExpression(rules, expression);
|
||||
return rules;
|
||||
}
|
||||
|
||||
@@ -31,55 +29,47 @@ public class OreDictFilterMatcher
|
||||
* @param expression expr to parse
|
||||
* @return the position of the expr. Is only relevant for sub rules
|
||||
*/
|
||||
public static int parseExpression( List<MatchRule> rules, String expression )
|
||||
{
|
||||
public static int parseExpression(List<MatchRule> rules, String expression) {
|
||||
rules.clear();
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for( int i = 0; i < expression.length(); i++ )
|
||||
{
|
||||
char c = expression.charAt( i );
|
||||
if( c == ' ' )
|
||||
{
|
||||
for (int i = 0; i < expression.length(); i++) {
|
||||
char c = expression.charAt(i);
|
||||
if (c == ' ') {
|
||||
continue;
|
||||
}
|
||||
if( c == '(' )
|
||||
{
|
||||
if (c == '(') {
|
||||
List<MatchRule> subRules = new ArrayList<>();
|
||||
i = parseExpression( subRules, expression.substring( i + 1 ) ) + i + 1;
|
||||
rules.add( MatchRule.group( subRules, builder.toString() ) );
|
||||
i = parseExpression(subRules, expression.substring(i + 1)) + i + 1;
|
||||
rules.add(MatchRule.group(subRules, builder.toString()));
|
||||
builder = new StringBuilder();
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ( c )
|
||||
{
|
||||
} else {
|
||||
switch (c) {
|
||||
case '&':
|
||||
rules.add( new MatchRule( builder.toString() ) );
|
||||
rules.add( new MatchRule( MatchLogic.AND ) );
|
||||
rules.add(new MatchRule(builder.toString()));
|
||||
rules.add(new MatchRule(MatchLogic.AND));
|
||||
builder = new StringBuilder();
|
||||
break;
|
||||
case '|':
|
||||
rules.add( new MatchRule( builder.toString() ) );
|
||||
rules.add( new MatchRule( MatchLogic.OR ) );
|
||||
rules.add(new MatchRule(builder.toString()));
|
||||
rules.add(new MatchRule(MatchLogic.OR));
|
||||
builder = new StringBuilder();
|
||||
break;
|
||||
case '^':
|
||||
rules.add( new MatchRule( builder.toString() ) );
|
||||
rules.add( new MatchRule( MatchLogic.XOR ) );
|
||||
rules.add(new MatchRule(builder.toString()));
|
||||
rules.add(new MatchRule(MatchLogic.XOR));
|
||||
builder = new StringBuilder();
|
||||
break;
|
||||
case ')':
|
||||
rules.add( new MatchRule( builder.toString() ) );
|
||||
rules.add(new MatchRule(builder.toString()));
|
||||
return i + 1;
|
||||
default:
|
||||
builder.append( c );
|
||||
builder.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
if( builder.length() > 0 )
|
||||
{
|
||||
rules.add( new MatchRule( builder.toString() ) );
|
||||
if (builder.length() > 0) {
|
||||
rules.add(new MatchRule(builder.toString()));
|
||||
}
|
||||
return expression.length();
|
||||
}
|
||||
@@ -92,39 +82,28 @@ public class OreDictFilterMatcher
|
||||
* @param oreDict string to check
|
||||
* @return if the string matches the rules
|
||||
*/
|
||||
public static boolean matches( List<MatchRule> rules, String oreDict )
|
||||
{
|
||||
public static boolean matches(List<MatchRule> rules, String oreDict) {
|
||||
boolean first = true;
|
||||
boolean lastResult = false;
|
||||
MatchLogic lastLogic = null;
|
||||
for( MatchRule rule : rules )
|
||||
{
|
||||
if( lastLogic == null )
|
||||
{
|
||||
if( rule.logic == MatchLogic.AND || rule.logic == MatchLogic.OR || rule.logic == MatchLogic.XOR )
|
||||
{
|
||||
for (MatchRule rule : rules) {
|
||||
if (lastLogic == null) {
|
||||
if (rule.logic == MatchLogic.AND || rule.logic == MatchLogic.OR || rule.logic == MatchLogic.XOR) {
|
||||
lastLogic = rule.logic;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if( lastLogic != null || first )
|
||||
{
|
||||
if( lastLogic != null )
|
||||
{
|
||||
switch ( lastLogic )
|
||||
{
|
||||
case AND:
|
||||
{
|
||||
if( !lastResult )
|
||||
{
|
||||
if (lastLogic != null || first) {
|
||||
if (lastLogic != null) {
|
||||
switch (lastLogic) {
|
||||
case AND: {
|
||||
if (!lastResult) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case OR:
|
||||
{
|
||||
if( lastResult )
|
||||
{
|
||||
case OR: {
|
||||
if (lastResult) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -133,19 +112,14 @@ public class OreDictFilterMatcher
|
||||
}
|
||||
|
||||
boolean newResult;
|
||||
if( rule.isGroup() )
|
||||
{
|
||||
newResult = rule.logic == MatchLogic.NOT ^ matches( rule.subRules, oreDict );
|
||||
}
|
||||
else
|
||||
{
|
||||
newResult = matches( rule, oreDict );
|
||||
if (rule.isGroup()) {
|
||||
newResult = rule.logic == MatchLogic.NOT ^ matches(rule.subRules, oreDict);
|
||||
} else {
|
||||
newResult = matches(rule, oreDict);
|
||||
}
|
||||
|
||||
if( lastLogic == MatchLogic.XOR )
|
||||
{
|
||||
if( lastResult == newResult )
|
||||
{
|
||||
if (lastLogic == MatchLogic.XOR) {
|
||||
if (lastResult == newResult) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -160,45 +134,37 @@ public class OreDictFilterMatcher
|
||||
return lastResult;
|
||||
}
|
||||
|
||||
private static boolean matches( MatchRule rule, String oreDict )
|
||||
{
|
||||
private static boolean matches(MatchRule rule, String oreDict) {
|
||||
String filter = rule.expression;
|
||||
|
||||
if( filter.equals( "*" ) )
|
||||
{
|
||||
if (filter.equals("*")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean startWild = filter.startsWith( "*" ), endWild = filter.endsWith( "*" );
|
||||
if( startWild )
|
||||
{
|
||||
filter = filter.substring( 1 );
|
||||
boolean startWild = filter.startsWith("*"), endWild = filter.endsWith("*");
|
||||
if (startWild) {
|
||||
filter = filter.substring(1);
|
||||
}
|
||||
|
||||
String[] parts = filter.split( "\\*+" );
|
||||
String[] parts = filter.split("\\*+");
|
||||
|
||||
return ( rule.logic == MatchLogic.NOT ) ^ matches( parts, oreDict, startWild, endWild );
|
||||
return (rule.logic == MatchLogic.NOT) ^ matches(parts, oreDict, startWild, endWild);
|
||||
}
|
||||
|
||||
private static boolean matches( String[] filter, String oreDict, boolean startWild, boolean endWild )
|
||||
{
|
||||
private static boolean matches(String[] filter, String oreDict, boolean startWild, boolean endWild) {
|
||||
String lastlastPart = filter[0];
|
||||
String lastPart = filter[0];
|
||||
int index = oreDict.indexOf( lastPart );
|
||||
if( ( !startWild && index != 0 ) || index < 0 )
|
||||
{
|
||||
int index = oreDict.indexOf(lastPart);
|
||||
if ((!startWild && index != 0) || index < 0) {
|
||||
return false;
|
||||
}
|
||||
boolean didGoBack = false;
|
||||
|
||||
for( int i = 1; i < filter.length; i++ )
|
||||
{
|
||||
for (int i = 1; i < filter.length; i++) {
|
||||
String part = filter[i];
|
||||
int newIndex = oreDict.indexOf( part, index + lastPart.length() );
|
||||
if( newIndex < 0 )
|
||||
{
|
||||
if( i > 1 && !didGoBack )
|
||||
{
|
||||
int newIndex = oreDict.indexOf(part, index + lastPart.length());
|
||||
if (newIndex < 0) {
|
||||
if (i > 1 && !didGoBack) {
|
||||
i -= 2;
|
||||
lastPart = lastlastPart;
|
||||
didGoBack = true;
|
||||
@@ -209,25 +175,20 @@ public class OreDictFilterMatcher
|
||||
lastlastPart = lastPart;
|
||||
lastPart = part;
|
||||
index = newIndex;
|
||||
if( didGoBack )
|
||||
{
|
||||
if (didGoBack) {
|
||||
didGoBack = false;
|
||||
}
|
||||
}
|
||||
|
||||
if( endWild || lastPart.length() + index == oreDict.length() )
|
||||
{
|
||||
if (endWild || lastPart.length() + index == oreDict.length()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for( int i = filter.length - 1; i < filter.length; i++ )
|
||||
{
|
||||
for (int i = filter.length - 1; i < filter.length; i++) {
|
||||
String part = filter[i];
|
||||
int newIndex = oreDict.indexOf( part, index + lastPart.length() );
|
||||
if( newIndex < 0 )
|
||||
{
|
||||
if( i > 1 && !didGoBack )
|
||||
{
|
||||
int newIndex = oreDict.indexOf(part, index + lastPart.length());
|
||||
if (newIndex < 0) {
|
||||
if (i > 1 && !didGoBack) {
|
||||
i -= 2;
|
||||
lastPart = lastlastPart;
|
||||
didGoBack = true;
|
||||
@@ -238,142 +199,115 @@ public class OreDictFilterMatcher
|
||||
lastlastPart = lastPart;
|
||||
lastPart = part;
|
||||
index = newIndex;
|
||||
if( didGoBack )
|
||||
{
|
||||
if (didGoBack) {
|
||||
didGoBack = false;
|
||||
}
|
||||
}
|
||||
return lastPart.length() + index == oreDict.length();
|
||||
}
|
||||
|
||||
public static String validateExp( String input )
|
||||
{
|
||||
public static String validateExp(String input) {
|
||||
// remove all operators that are double
|
||||
input = input.replaceAll( "\\*{2,}", "*" );
|
||||
input = input.replaceAll( "&{2,}", "&" );
|
||||
input = input.replaceAll( "\\|{2,}", "|" );
|
||||
input = input.replaceAll( "!{2,}", "!" );
|
||||
input = input.replaceAll( "\\^{2,}", "^" );
|
||||
input = input.replaceAll( " {2,}", " " );
|
||||
input = input.replaceAll("\\*{2,}", "*");
|
||||
input = input.replaceAll("&{2,}", "&");
|
||||
input = input.replaceAll("\\|{2,}", "|");
|
||||
input = input.replaceAll("!{2,}", "!");
|
||||
input = input.replaceAll("\\^{2,}", "^");
|
||||
input = input.replaceAll(" {2,}", " ");
|
||||
// move ( and ) so it doesn't create invalid expressions f.e. xxx (& yyy) => xxx & (yyy)
|
||||
// append or prepend ( and ) if the amount is not equal
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int unclosed = 0;
|
||||
char last = ' ';
|
||||
for( int i = 0; i < input.length(); i++ )
|
||||
{
|
||||
char c = input.charAt( i );
|
||||
if( c == ' ' )
|
||||
{
|
||||
if( last != '(' )
|
||||
{
|
||||
builder.append( " " );
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
char c = input.charAt(i);
|
||||
if (c == ' ') {
|
||||
if (last != '(') {
|
||||
builder.append(" ");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if( c == '(' )
|
||||
{
|
||||
if (c == '(') {
|
||||
unclosed++;
|
||||
}
|
||||
else if( c == ')' )
|
||||
{
|
||||
} else if (c == ')') {
|
||||
unclosed--;
|
||||
if( last == '&' || last == '|' || last == '^' )
|
||||
{
|
||||
int l = builder.lastIndexOf( " " + last );
|
||||
int l2 = builder.lastIndexOf( "" + last );
|
||||
builder.insert( l == l2 - 1 ? l : l2, ")" );
|
||||
if (last == '&' || last == '|' || last == '^') {
|
||||
int l = builder.lastIndexOf(" " + last);
|
||||
int l2 = builder.lastIndexOf("" + last);
|
||||
builder.insert(l == l2 - 1 ? l : l2, ")");
|
||||
continue;
|
||||
}
|
||||
if( i > 0 && builder.charAt( builder.length() - 1 ) == ' ' )
|
||||
{
|
||||
builder.deleteCharAt( builder.length() - 1 );
|
||||
if (i > 0 && builder.charAt(builder.length() - 1) == ' ') {
|
||||
builder.deleteCharAt(builder.length() - 1);
|
||||
}
|
||||
}
|
||||
else if( ( c == '&' || c == '|' || c == '^' ) && last == '(' )
|
||||
{
|
||||
builder.deleteCharAt( builder.lastIndexOf( "(" ) );
|
||||
builder.append( c ).append( " (" );
|
||||
} else if ((c == '&' || c == '|' || c == '^') && last == '(') {
|
||||
builder.deleteCharAt(builder.lastIndexOf("("));
|
||||
builder.append(c).append(" (");
|
||||
continue;
|
||||
}
|
||||
|
||||
builder.append( c );
|
||||
builder.append(c);
|
||||
last = c;
|
||||
}
|
||||
if( unclosed > 0 )
|
||||
{
|
||||
for( int i = 0; i < unclosed; i++ )
|
||||
{
|
||||
builder.append( ")" );
|
||||
if (unclosed > 0) {
|
||||
for (int i = 0; i < unclosed; i++) {
|
||||
builder.append(")");
|
||||
}
|
||||
}
|
||||
else if( unclosed < 0 )
|
||||
{
|
||||
} else if (unclosed < 0) {
|
||||
unclosed = -unclosed;
|
||||
for( int i = 0; i < unclosed; i++ )
|
||||
{
|
||||
builder.insert( 0, "(" );
|
||||
for (int i = 0; i < unclosed; i++) {
|
||||
builder.insert(0, "(");
|
||||
}
|
||||
}
|
||||
input = builder.toString();
|
||||
input = input.replaceAll( " {2,}", " " );
|
||||
input = input.replaceAll(" {2,}", " ");
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
public static class MatchRule
|
||||
{
|
||||
public static class MatchRule {
|
||||
public final MatchLogic logic;
|
||||
public final String expression;
|
||||
private final List<MatchRule> subRules;
|
||||
|
||||
private MatchRule( MatchLogic logic, String expression, List<MatchRule> subRules )
|
||||
{
|
||||
if( expression.startsWith( "!" ) )
|
||||
{
|
||||
private MatchRule(MatchLogic logic, String expression, List<MatchRule> subRules) {
|
||||
if (expression.startsWith("!")) {
|
||||
logic = MatchLogic.NOT;
|
||||
expression = expression.substring( 1 );
|
||||
expression = expression.substring(1);
|
||||
}
|
||||
this.logic = logic;
|
||||
this.expression = expression;
|
||||
this.subRules = subRules;
|
||||
}
|
||||
|
||||
public MatchRule( MatchLogic logic, String expression )
|
||||
{
|
||||
this( logic, expression, null );
|
||||
public MatchRule(MatchLogic logic, String expression) {
|
||||
this(logic, expression, null);
|
||||
}
|
||||
|
||||
public MatchRule( MatchLogic logic )
|
||||
{
|
||||
this( logic, "" );
|
||||
public MatchRule(MatchLogic logic) {
|
||||
this(logic, "");
|
||||
}
|
||||
|
||||
public MatchRule( String expression )
|
||||
{
|
||||
this( MatchLogic.ANY, expression );
|
||||
public MatchRule(String expression) {
|
||||
this(MatchLogic.ANY, expression);
|
||||
}
|
||||
|
||||
public static MatchRule not( String expression, boolean not )
|
||||
{
|
||||
return new MatchRule( not ? MatchLogic.NOT : MatchLogic.ANY, expression );
|
||||
public static MatchRule not(String expression, boolean not) {
|
||||
return new MatchRule(not ? MatchLogic.NOT : MatchLogic.ANY, expression);
|
||||
}
|
||||
|
||||
public static MatchRule group( List<MatchRule> subRules, String expression )
|
||||
{
|
||||
MatchLogic logic = expression.startsWith( "!" ) ? MatchLogic.NOT : MatchLogic.ANY;
|
||||
return new MatchRule( logic, "", subRules );
|
||||
public static MatchRule group(List<MatchRule> subRules, String expression) {
|
||||
MatchLogic logic = expression.startsWith("!") ? MatchLogic.NOT : MatchLogic.ANY;
|
||||
return new MatchRule(logic, "", subRules);
|
||||
}
|
||||
|
||||
public boolean isGroup()
|
||||
{
|
||||
public boolean isGroup() {
|
||||
return subRules != null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public enum MatchLogic
|
||||
{
|
||||
public enum MatchLogic {
|
||||
OR,
|
||||
AND,
|
||||
XOR,
|
||||
|
||||
@@ -30,22 +30,19 @@ import net.minecraftforge.oredict.OreDictionary;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class OreHelper
|
||||
{
|
||||
public class OreHelper {
|
||||
|
||||
public static final OreHelper INSTANCE = new OreHelper();
|
||||
|
||||
/**
|
||||
* A local cache to speed up OreDictionary lookups.
|
||||
*/
|
||||
private final LoadingCache<String, List<ItemStack>> oreDictCache = CacheBuilder.newBuilder().build( new CacheLoader<String, List<ItemStack>>()
|
||||
{
|
||||
private final LoadingCache<String, List<ItemStack>> oreDictCache = CacheBuilder.newBuilder().build(new CacheLoader<String, List<ItemStack>>() {
|
||||
@Override
|
||||
public List<ItemStack> load( final String oreName )
|
||||
{
|
||||
return OreDictionary.getOres( oreName );
|
||||
public List<ItemStack> load(final String oreName) {
|
||||
return OreDictionary.getOres(oreName);
|
||||
}
|
||||
} );
|
||||
});
|
||||
|
||||
private final Map<ItemRef, OreReference> references = new HashMap<>();
|
||||
|
||||
@@ -55,80 +52,64 @@ public class OreHelper
|
||||
* @param itemStack the itemstack to test
|
||||
* @return true if an ore entry exists, false otherwise
|
||||
*/
|
||||
public Optional<OreReference> getOre( final ItemStack itemStack )
|
||||
{
|
||||
final ItemRef ir = new ItemRef( itemStack );
|
||||
public Optional<OreReference> getOre(final ItemStack itemStack) {
|
||||
final ItemRef ir = new ItemRef(itemStack);
|
||||
|
||||
if( !this.references.containsKey( ir ) )
|
||||
{
|
||||
if (!this.references.containsKey(ir)) {
|
||||
final OreReference ref = new OreReference();
|
||||
final Collection<Integer> ores = ref.getOres();
|
||||
final Collection<String> set = ref.getEquivalents();
|
||||
|
||||
final Set<String> toAdd = new HashSet<>();
|
||||
|
||||
for( final String ore : OreDictionary.getOreNames() )
|
||||
{
|
||||
for (final String ore : OreDictionary.getOreNames()) {
|
||||
// skip ore if it is a match already or null.
|
||||
if( ore == null || toAdd.contains( ore ) )
|
||||
{
|
||||
if (ore == null || toAdd.contains(ore)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for( final ItemStack oreItem : this.oreDictCache.getUnchecked( ore ) )
|
||||
{
|
||||
if( OreDictionary.itemMatches( oreItem, itemStack, false ) )
|
||||
{
|
||||
toAdd.add( ore );
|
||||
for (final ItemStack oreItem : this.oreDictCache.getUnchecked(ore)) {
|
||||
if (OreDictionary.itemMatches(oreItem, itemStack, false)) {
|
||||
toAdd.add(ore);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( final String ore : toAdd )
|
||||
{
|
||||
set.add( ore );
|
||||
ores.add( OreDictionary.getOreID( ore ) );
|
||||
for (final String ore : toAdd) {
|
||||
set.add(ore);
|
||||
ores.add(OreDictionary.getOreID(ore));
|
||||
}
|
||||
|
||||
if( !set.isEmpty() )
|
||||
{
|
||||
this.references.put( ir, ref );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.references.put( ir, null );
|
||||
if (!set.isEmpty()) {
|
||||
this.references.put(ir, ref);
|
||||
} else {
|
||||
this.references.put(ir, null);
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.ofNullable( this.references.get( ir ) );
|
||||
return Optional.ofNullable(this.references.get(ir));
|
||||
}
|
||||
|
||||
boolean sameOre( final AEItemStack aeItemStack, final IAEItemStack is )
|
||||
{
|
||||
final OreReference a = aeItemStack.getOre().orElse( null );
|
||||
final OreReference b = ( (AEItemStack) is ).getOre().orElse( null );
|
||||
boolean sameOre(final AEItemStack aeItemStack, final IAEItemStack is) {
|
||||
final OreReference a = aeItemStack.getOre().orElse(null);
|
||||
final OreReference b = ((AEItemStack) is).getOre().orElse(null);
|
||||
|
||||
return this.sameOre( a, b );
|
||||
return this.sameOre(a, b);
|
||||
}
|
||||
|
||||
public boolean sameOre( final OreReference a, final OreReference b )
|
||||
{
|
||||
if( a == null || b == null )
|
||||
{
|
||||
public boolean sameOre(final OreReference a, final OreReference b) {
|
||||
if (a == null || b == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( a == b )
|
||||
{
|
||||
if (a == b) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final Collection<Integer> bOres = b.getOres();
|
||||
for( final Integer ore : a.getOres() )
|
||||
{
|
||||
if( bOres.contains( ore ) )
|
||||
{
|
||||
for (final Integer ore : a.getOres()) {
|
||||
if (bOres.contains(ore)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -136,60 +117,47 @@ public class OreHelper
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean sameOre( final AEItemStack aeItemStack, final ItemStack o )
|
||||
{
|
||||
return aeItemStack.getOre().map( a -> {
|
||||
for( final String oreName : a.getEquivalents() )
|
||||
{
|
||||
for( final ItemStack oreItem : this.oreDictCache.getUnchecked( oreName ) )
|
||||
{
|
||||
if( OreDictionary.itemMatches( oreItem, o, false ) )
|
||||
{
|
||||
boolean sameOre(final AEItemStack aeItemStack, final ItemStack o) {
|
||||
return aeItemStack.getOre().map(a -> {
|
||||
for (final String oreName : a.getEquivalents()) {
|
||||
for (final ItemStack oreItem : this.oreDictCache.getUnchecked(oreName)) {
|
||||
if (OreDictionary.itemMatches(oreItem, o, false)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} ).orElse( false );
|
||||
}).orElse(false);
|
||||
}
|
||||
|
||||
public Set<Integer> getMatchingOre( String oreExp )
|
||||
{
|
||||
public Set<Integer> getMatchingOre(String oreExp) {
|
||||
Set<Integer> matchingIds = new HashSet<>();
|
||||
|
||||
List<OreDictFilterMatcher.MatchRule> rulesList = OreDictFilterMatcher.parseExpression( oreExp );
|
||||
for( String ore : OreDictionary.getOreNames() )
|
||||
{
|
||||
if( OreDictFilterMatcher.matches( rulesList, ore ) )
|
||||
{
|
||||
matchingIds.add( OreDictionary.getOreID( ore ) );
|
||||
List<OreDictFilterMatcher.MatchRule> rulesList = OreDictFilterMatcher.parseExpression(oreExp);
|
||||
for (String ore : OreDictionary.getOreNames()) {
|
||||
if (OreDictFilterMatcher.matches(rulesList, ore)) {
|
||||
matchingIds.add(OreDictionary.getOreID(ore));
|
||||
}
|
||||
}
|
||||
return matchingIds;
|
||||
}
|
||||
|
||||
public List<ItemStack> getCachedOres( final String oreName )
|
||||
{
|
||||
return this.oreDictCache.getUnchecked( oreName );
|
||||
public List<ItemStack> getCachedOres(final String oreName) {
|
||||
return this.oreDictCache.getUnchecked(oreName);
|
||||
}
|
||||
|
||||
private static class ItemRef
|
||||
{
|
||||
private static class ItemRef {
|
||||
|
||||
private final Item ref;
|
||||
private final int damage;
|
||||
private final int hash;
|
||||
|
||||
ItemRef( final ItemStack stack )
|
||||
{
|
||||
ItemRef(final ItemStack stack) {
|
||||
this.ref = stack.getItem();
|
||||
|
||||
if( stack.getItem().isDamageable() )
|
||||
{
|
||||
if (stack.getItem().isDamageable()) {
|
||||
this.damage = 0; // IGNORED
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
this.damage = stack.getItemDamage(); // might be important...
|
||||
}
|
||||
|
||||
@@ -197,20 +165,16 @@ public class OreHelper
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
return this.hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( final Object obj )
|
||||
{
|
||||
if( obj == null )
|
||||
{
|
||||
public boolean equals(final Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if( this.getClass() != obj.getClass() )
|
||||
{
|
||||
if (this.getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final ItemRef other = (ItemRef) obj;
|
||||
@@ -218,8 +182,7 @@ public class OreHelper
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
return "ItemRef [ref=" + this.ref.getUnlocalizedName() + ", damage=" + this.damage + ", hash=" + this.hash + ']';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,54 +19,41 @@
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class OreReference
|
||||
{
|
||||
public class OreReference {
|
||||
|
||||
private final List<String> otherOptions = new ArrayList<>();
|
||||
private final Set<Integer> ores = new HashSet<>();
|
||||
private List<IAEItemStack> aeOtherOptions = null;
|
||||
private final List<String> otherOptions = new ArrayList<>();
|
||||
private final Set<Integer> ores = new HashSet<>();
|
||||
private List<IAEItemStack> aeOtherOptions = null;
|
||||
|
||||
Collection<String> getEquivalents()
|
||||
{
|
||||
return this.otherOptions;
|
||||
}
|
||||
Collection<String> getEquivalents() {
|
||||
return this.otherOptions;
|
||||
}
|
||||
|
||||
public List<IAEItemStack> getAEEquivalents()
|
||||
{
|
||||
if( this.aeOtherOptions == null )
|
||||
{
|
||||
this.aeOtherOptions = new ArrayList<>( this.otherOptions.size() );
|
||||
public List<IAEItemStack> getAEEquivalents() {
|
||||
if (this.aeOtherOptions == null) {
|
||||
this.aeOtherOptions = new ArrayList<>(this.otherOptions.size());
|
||||
|
||||
// SUMMON AE STACKS!
|
||||
for( final String oreName : this.otherOptions )
|
||||
{
|
||||
for( final ItemStack is : OreHelper.INSTANCE.getCachedOres( oreName ) )
|
||||
{
|
||||
if( is.getItem() != Items.AIR )
|
||||
{
|
||||
this.aeOtherOptions.add( AEItemStack.fromItemStack( is ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// SUMMON AE STACKS!
|
||||
for (final String oreName : this.otherOptions) {
|
||||
for (final ItemStack is : OreHelper.INSTANCE.getCachedOres(oreName)) {
|
||||
if (is.getItem() != Items.AIR) {
|
||||
this.aeOtherOptions.add(AEItemStack.fromItemStack(is));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.aeOtherOptions;
|
||||
}
|
||||
return this.aeOtherOptions;
|
||||
}
|
||||
|
||||
public Collection<Integer> getOres()
|
||||
{
|
||||
public Collection<Integer> getOres() {
|
||||
return this.ores;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,44 +19,39 @@
|
||||
package appeng.util.iterators;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public final class AEInvIterator implements Iterator<IAEItemStack>
|
||||
{
|
||||
private final AppEngInternalAEInventory inventory;
|
||||
private final int size;
|
||||
|
||||
private int counter = 0;
|
||||
public final class AEInvIterator implements Iterator<IAEItemStack> {
|
||||
private final AppEngInternalAEInventory inventory;
|
||||
private final int size;
|
||||
|
||||
public AEInvIterator( final AppEngInternalAEInventory inventory )
|
||||
{
|
||||
this.inventory = inventory;
|
||||
this.size = this.inventory.getSlots();
|
||||
}
|
||||
private int counter = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return this.counter < this.size;
|
||||
}
|
||||
public AEInvIterator(final AppEngInternalAEInventory inventory) {
|
||||
this.inventory = inventory;
|
||||
this.size = this.inventory.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack next()
|
||||
{
|
||||
final IAEItemStack result = this.inventory.getAEStackInSlot( this.counter );
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.counter < this.size;
|
||||
}
|
||||
|
||||
this.counter++;
|
||||
@Override
|
||||
public IAEItemStack next() {
|
||||
final IAEItemStack result = this.inventory.getAEStackInSlot(this.counter);
|
||||
|
||||
return result;
|
||||
}
|
||||
this.counter++;
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,34 +22,29 @@ package appeng.util.iterators;
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
public final class ChainedIterator<T> implements Iterator<T>
|
||||
{
|
||||
private final T[] list;
|
||||
public final class ChainedIterator<T> implements Iterator<T> {
|
||||
private final T[] list;
|
||||
|
||||
private int offset = 0;
|
||||
private int offset = 0;
|
||||
|
||||
public ChainedIterator( final T... list )
|
||||
{
|
||||
this.list = list;
|
||||
}
|
||||
public ChainedIterator(final T... list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return this.offset < this.list.length;
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.offset < this.list.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next()
|
||||
{
|
||||
final T result = this.list[this.offset];
|
||||
this.offset++;
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public T next() {
|
||||
final T result = this.list[this.offset];
|
||||
this.offset++;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,43 +19,38 @@
|
||||
package appeng.util.iterators;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public final class InvIterator implements Iterator<ItemStack>
|
||||
{
|
||||
private final IItemHandler inventory;
|
||||
private final int size;
|
||||
|
||||
private int counter = 0;
|
||||
public final class InvIterator implements Iterator<ItemStack> {
|
||||
private final IItemHandler inventory;
|
||||
private final int size;
|
||||
|
||||
public InvIterator( final IItemHandler inventory )
|
||||
{
|
||||
this.inventory = inventory;
|
||||
this.size = this.inventory.getSlots();
|
||||
}
|
||||
private int counter = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return this.counter < this.size;
|
||||
}
|
||||
public InvIterator(final IItemHandler inventory) {
|
||||
this.inventory = inventory;
|
||||
this.size = this.inventory.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack next()
|
||||
{
|
||||
final ItemStack result = this.inventory.getStackInSlot( this.counter );
|
||||
this.counter++;
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.counter < this.size;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public ItemStack next() {
|
||||
final ItemStack result = this.inventory.getStackInSlot(this.counter);
|
||||
this.counter++;
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,24 +22,20 @@ package appeng.util.iterators;
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
public class NullIterator<T> implements Iterator<T>
|
||||
{
|
||||
public class NullIterator<T> implements Iterator<T> {
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public T next() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
@Override
|
||||
public void remove() {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,38 +19,33 @@
|
||||
package appeng.util.iterators;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public final class ProxyNodeIterator implements Iterator<IGridNode>
|
||||
{
|
||||
private final Iterator<IGridHost> hosts;
|
||||
|
||||
public ProxyNodeIterator( final Iterator<IGridHost> hosts )
|
||||
{
|
||||
this.hosts = hosts;
|
||||
}
|
||||
public final class ProxyNodeIterator implements Iterator<IGridNode> {
|
||||
private final Iterator<IGridHost> hosts;
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return this.hosts.hasNext();
|
||||
}
|
||||
public ProxyNodeIterator(final Iterator<IGridHost> hosts) {
|
||||
this.hosts = hosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode next()
|
||||
{
|
||||
final IGridHost host = this.hosts.next();
|
||||
return host.getGridNode( AEPartLocation.INTERNAL );
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.hosts.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@Override
|
||||
public IGridNode next() {
|
||||
final IGridHost host = this.hosts.next();
|
||||
return host.getGridNode(AEPartLocation.INTERNAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,43 +19,37 @@
|
||||
package appeng.util.iterators;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.util.inv.ItemSlot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.util.inv.ItemSlot;
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
public class StackToSlotIterator implements Iterator<ItemSlot>
|
||||
{
|
||||
public class StackToSlotIterator implements Iterator<ItemSlot> {
|
||||
|
||||
private final ItemSlot iss = new ItemSlot();
|
||||
private final Iterator<ItemStack> is;
|
||||
private int x = 0;
|
||||
private final ItemSlot iss = new ItemSlot();
|
||||
private final Iterator<ItemStack> is;
|
||||
private int x = 0;
|
||||
|
||||
public StackToSlotIterator( final Iterator<ItemStack> is )
|
||||
{
|
||||
this.is = is;
|
||||
}
|
||||
public StackToSlotIterator(final Iterator<ItemStack> is) {
|
||||
this.is = is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return this.is.hasNext();
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.is.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemSlot next()
|
||||
{
|
||||
this.iss.setSlot( this.x );
|
||||
this.x++;
|
||||
this.iss.setItemStack( this.is.next() );
|
||||
return this.iss;
|
||||
}
|
||||
@Override
|
||||
public ItemSlot next() {
|
||||
this.iss.setSlot(this.x);
|
||||
this.x++;
|
||||
this.iss.setItemStack(this.is.next());
|
||||
return this.iss;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
// uhh no.
|
||||
}
|
||||
@Override
|
||||
public void remove() {
|
||||
// uhh no.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,29 +19,25 @@
|
||||
package appeng.util.prioritylist;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class DefaultPriorityList<T extends IAEStack<T>> implements IPartitionList<T>
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean isListed( final T input )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
public class DefaultPriorityList<T extends IAEStack<T>> implements IPartitionList<T> {
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isListed(final T input) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> getItems()
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> getItems() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,41 +19,36 @@
|
||||
package appeng.util.prioritylist;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class FuzzyPriorityList<T extends IAEStack<T>> implements IPartitionList<T>
|
||||
{
|
||||
|
||||
private final IItemList<T> list;
|
||||
private final FuzzyMode mode;
|
||||
public class FuzzyPriorityList<T extends IAEStack<T>> implements IPartitionList<T> {
|
||||
|
||||
public FuzzyPriorityList( final IItemList<T> in, final FuzzyMode mode )
|
||||
{
|
||||
this.list = in;
|
||||
this.mode = mode;
|
||||
}
|
||||
private final IItemList<T> list;
|
||||
private final FuzzyMode mode;
|
||||
|
||||
@Override
|
||||
public boolean isListed( final T input )
|
||||
{
|
||||
final Collection<T> out = this.list.findFuzzy( input, this.mode );
|
||||
return out != null && !out.isEmpty();
|
||||
}
|
||||
public FuzzyPriorityList(final IItemList<T> in, final FuzzyMode mode) {
|
||||
this.list = in;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return this.list.isEmpty();
|
||||
}
|
||||
@Override
|
||||
public boolean isListed(final T input) {
|
||||
final Collection<T> out = this.list.findFuzzy(input, this.mode);
|
||||
return out != null && !out.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> getItems()
|
||||
{
|
||||
return this.list;
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.list.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> getItems() {
|
||||
return this.list;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,11 +22,10 @@ package appeng.util.prioritylist;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
|
||||
public interface IPartitionList<T extends IAEStack<T>>
|
||||
{
|
||||
boolean isListed( T input );
|
||||
public interface IPartitionList<T extends IAEStack<T>> {
|
||||
boolean isListed(T input);
|
||||
|
||||
boolean isEmpty();
|
||||
boolean isEmpty();
|
||||
|
||||
Iterable<T> getItems();
|
||||
Iterable<T> getItems();
|
||||
}
|
||||
|
||||
@@ -19,66 +19,53 @@
|
||||
package appeng.util.prioritylist;
|
||||
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
public final class MergedPriorityList<T extends IAEStack<T>> implements IPartitionList<T> {
|
||||
|
||||
public final class MergedPriorityList<T extends IAEStack<T>> implements IPartitionList<T>
|
||||
{
|
||||
private final Collection<IPartitionList<T>> positive = new ArrayList<>();
|
||||
private final Collection<IPartitionList<T>> negative = new ArrayList<>();
|
||||
|
||||
private final Collection<IPartitionList<T>> positive = new ArrayList<>();
|
||||
private final Collection<IPartitionList<T>> negative = new ArrayList<>();
|
||||
public void addNewList(final IPartitionList<T> list, final boolean isWhitelist) {
|
||||
if (isWhitelist) {
|
||||
this.positive.add(list);
|
||||
} else {
|
||||
this.negative.add(list);
|
||||
}
|
||||
}
|
||||
|
||||
public void addNewList( final IPartitionList<T> list, final boolean isWhitelist )
|
||||
{
|
||||
if( isWhitelist )
|
||||
{
|
||||
this.positive.add( list );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.negative.add( list );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean isListed(final T input) {
|
||||
for (final IPartitionList<T> l : this.negative) {
|
||||
if (l.isListed(input)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isListed( final T input )
|
||||
{
|
||||
for( final IPartitionList<T> l : this.negative )
|
||||
{
|
||||
if( l.isListed( input ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!this.positive.isEmpty()) {
|
||||
for (final IPartitionList<T> l : this.positive) {
|
||||
if (l.isListed(input)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if( !this.positive.isEmpty() )
|
||||
{
|
||||
for( final IPartitionList<T> l : this.positive )
|
||||
{
|
||||
if( l.isListed( input ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.positive.isEmpty() && this.negative.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return this.positive.isEmpty() && this.negative.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> getItems()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@Override
|
||||
public Iterable<T> getItems() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,27 +8,21 @@ import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class OreDictPriorityList<T extends IAEStack<T>> implements IPartitionList<T>
|
||||
{
|
||||
public class OreDictPriorityList<T extends IAEStack<T>> implements IPartitionList<T> {
|
||||
private final Set<Integer> oreIDs;
|
||||
private final String oreMatch;
|
||||
|
||||
public OreDictPriorityList( Set<Integer> oreIDs, String oreMatch )
|
||||
{
|
||||
public OreDictPriorityList(Set<Integer> oreIDs, String oreMatch) {
|
||||
this.oreIDs = oreIDs;
|
||||
this.oreMatch = oreMatch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isListed( final T input )
|
||||
{
|
||||
OreReference or = ( (AEItemStack) input ).getOre().orElse( null );
|
||||
if( or != null )
|
||||
{
|
||||
for( Integer oreID : or.getOres() )
|
||||
{
|
||||
if( this.oreIDs.contains( oreID ) )
|
||||
{
|
||||
public boolean isListed(final T input) {
|
||||
OreReference or = ((AEItemStack) input).getOre().orElse(null);
|
||||
if (or != null) {
|
||||
for (Integer oreID : or.getOres()) {
|
||||
if (this.oreIDs.contains(oreID)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -37,14 +31,12 @@ public class OreDictPriorityList<T extends IAEStack<T>> implements IPartitionLis
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return oreMatch.equals( "" );
|
||||
public boolean isEmpty() {
|
||||
return oreMatch.equals("");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> getItems()
|
||||
{
|
||||
public Iterable<T> getItems() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,31 +23,26 @@ import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
|
||||
public class PrecisePriorityList<T extends IAEStack<T>> implements IPartitionList<T>
|
||||
{
|
||||
public class PrecisePriorityList<T extends IAEStack<T>> implements IPartitionList<T> {
|
||||
|
||||
private final IItemList<T> list;
|
||||
private final IItemList<T> list;
|
||||
|
||||
public PrecisePriorityList( final IItemList<T> in )
|
||||
{
|
||||
this.list = in;
|
||||
}
|
||||
public PrecisePriorityList(final IItemList<T> in) {
|
||||
this.list = in;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isListed( final T input )
|
||||
{
|
||||
return this.list.findPrecise( input ) != null;
|
||||
}
|
||||
@Override
|
||||
public boolean isListed(final T input) {
|
||||
return this.list.findPrecise(input) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return this.list.isEmpty();
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.list.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> getItems()
|
||||
{
|
||||
return this.list;
|
||||
}
|
||||
@Override
|
||||
public Iterable<T> getItems() {
|
||||
return this.list;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user