pick 97420a31d The big reformat of 2020
This commit is contained in:
@@ -18,28 +18,22 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean call( final World world ) throws Exception
|
||||
{
|
||||
if( world.isBlockLoaded( this.pos ) )
|
||||
{
|
||||
world.notifyNeighborsOfStateChange( this.pos, Platform.AIR_BLOCK );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,104 +18,80 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -31,102 +30,84 @@ import appeng.api.config.StorageFilter;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.core.AELog;
|
||||
|
||||
public final class ConfigManager implements IConfigManager {
|
||||
private final Map<Settings, Enum<?>> settings = new EnumMap<>(Settings.class);
|
||||
private final IConfigManagerHost target;
|
||||
|
||||
public final class ConfigManager implements IConfigManager
|
||||
{
|
||||
private final Map<Settings, Enum<?>> settings = new EnumMap<>( Settings.class );
|
||||
private final IConfigManagerHost target;
|
||||
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.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.target.updateSetting( this, settingName, newValue );
|
||||
return oldValue;
|
||||
}
|
||||
/**
|
||||
* save all settings using config manager.
|
||||
*
|
||||
* @param tagCompound to be written to compound
|
||||
*/
|
||||
@Override
|
||||
public void writeToNBT(final CompoundNBT tagCompound) {
|
||||
for (final Map.Entry<Settings, Enum<?>> entry : this.settings.entrySet()) {
|
||||
tagCompound.putString(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 CompoundNBT tagCompound )
|
||||
{
|
||||
for( final Map.Entry<Settings, Enum<?>> entry : this.settings.entrySet() )
|
||||
{
|
||||
tagCompound.putString( 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 CompoundNBT tagCompound) {
|
||||
for (final Map.Entry<Settings, Enum<?>> entry : this.settings.entrySet()) {
|
||||
try {
|
||||
if (tagCompound.contains(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 CompoundNBT tagCompound )
|
||||
{
|
||||
for( final Map.Entry<Settings, Enum<?>> entry : this.settings.entrySet() )
|
||||
{
|
||||
try
|
||||
{
|
||||
if( tagCompound.contains( 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,28 +3,22 @@ package appeng.util;
|
||||
import java.util.EnumSet;
|
||||
|
||||
/**
|
||||
* Simple utility class to help with select the "next" or "previous" value in a list of options represented
|
||||
* by an enumeration.
|
||||
* Simple utility class to help with select the "next" or "previous" value in a
|
||||
* list of options represented by an enumeration.
|
||||
*/
|
||||
public final class EnumCycler {
|
||||
|
||||
private EnumCycler() {
|
||||
}
|
||||
|
||||
public static <T extends Enum<T>> T rotateEnum( T ce, final boolean backwards, final EnumSet<T> validOptions )
|
||||
{
|
||||
do
|
||||
{
|
||||
if( backwards )
|
||||
{
|
||||
ce = prevEnum( ce );
|
||||
public static <T extends Enum<T>> T rotateEnum(T ce, final boolean backwards, final EnumSet<T> validOptions) {
|
||||
do {
|
||||
if (backwards) {
|
||||
ce = prevEnum(ce);
|
||||
} else {
|
||||
ce = next(ce);
|
||||
}
|
||||
else
|
||||
{
|
||||
ce = next( ce );
|
||||
}
|
||||
}
|
||||
while( !validOptions.contains( ce ) );
|
||||
} while (!validOptions.contains(ce));
|
||||
|
||||
return ce;
|
||||
}
|
||||
@@ -32,18 +26,15 @@ public final class EnumCycler {
|
||||
/*
|
||||
* Simple way to cycle an enum...
|
||||
*/
|
||||
public static <T extends Enum<T>> T prevEnum( final T ce )
|
||||
{
|
||||
public static <T extends Enum<T>> T prevEnum(final T ce) {
|
||||
T[] values = ce.getDeclaringClass().getEnumConstants();
|
||||
|
||||
int pLoc = ce.ordinal() - 1;
|
||||
if( pLoc < 0 )
|
||||
{
|
||||
if (pLoc < 0) {
|
||||
pLoc = values.length - 1;
|
||||
}
|
||||
|
||||
if( pLoc < 0 || pLoc >= values.length )
|
||||
{
|
||||
if (pLoc < 0 || pLoc >= values.length) {
|
||||
pLoc = 0;
|
||||
}
|
||||
|
||||
@@ -53,18 +44,15 @@ public final class EnumCycler {
|
||||
/*
|
||||
* Simple way to cycle an enum...
|
||||
*/
|
||||
public static <T extends Enum<T>> T next(final T ce )
|
||||
{
|
||||
public static <T extends Enum<T>> T next(final T ce) {
|
||||
T[] values = ce.getDeclaringClass().getEnumConstants();
|
||||
|
||||
int pLoc = ce.ordinal() + 1;
|
||||
if( pLoc >= values.length )
|
||||
{
|
||||
if (pLoc >= values.length) {
|
||||
pLoc = 0;
|
||||
}
|
||||
|
||||
if( pLoc < 0 || pLoc >= values.length )
|
||||
{
|
||||
if (pLoc < 0 || pLoc >= values.length) {
|
||||
pLoc = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,13 +18,10 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.util.IConfigManager;
|
||||
|
||||
public interface IConfigManagerHost {
|
||||
|
||||
public interface IConfigManagerHost
|
||||
{
|
||||
|
||||
void updateSetting(IConfigManager manager, Settings settingName, Enum<?> newValue );
|
||||
void updateSetting(IConfigManager manager, Settings settingName, Enum<?> newValue);
|
||||
}
|
||||
|
||||
@@ -18,32 +18,27 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
|
||||
|
||||
/**
|
||||
* Limits a number converter to a char width of at max 3 characters.
|
||||
* This is generally used for players, who activated the large font extension.
|
||||
* Limits a number converter to a char width of at max 3 characters. This is
|
||||
* generally used for players, who activated the large font extension.
|
||||
*
|
||||
* @author thatsIch
|
||||
* @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
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
|
||||
@@ -18,10 +18,8 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
|
||||
|
||||
/**
|
||||
* Limits a number converter to a char width of at max 4 characters
|
||||
*
|
||||
@@ -29,20 +27,17 @@ 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
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
|
||||
@@ -18,35 +18,34 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
||||
/**
|
||||
* An interface similar to {@link Callable}, but allowing to pass the {@link World} when calling.
|
||||
* An interface similar to {@link Callable}, but allowing to pass the
|
||||
* {@link World} when calling.
|
||||
*
|
||||
* @author yueh
|
||||
* @version rv3
|
||||
* @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;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -27,62 +26,51 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class InWorldToolOperationResult {
|
||||
|
||||
public class InWorldToolOperationResult
|
||||
{
|
||||
private final BlockState blockState;
|
||||
private final List<ItemStack> drops;
|
||||
|
||||
private final BlockState blockState;
|
||||
private final List<ItemStack> drops;
|
||||
public InWorldToolOperationResult() {
|
||||
this.blockState = null;
|
||||
this.drops = null;
|
||||
}
|
||||
|
||||
public InWorldToolOperationResult()
|
||||
{
|
||||
this.blockState = null;
|
||||
this.drops = null;
|
||||
}
|
||||
public InWorldToolOperationResult(final BlockState block, final List<ItemStack> drops) {
|
||||
this.blockState = block;
|
||||
this.drops = drops;
|
||||
}
|
||||
|
||||
public InWorldToolOperationResult( final BlockState block, final List<ItemStack> drops )
|
||||
{
|
||||
this.blockState = block;
|
||||
this.drops = drops;
|
||||
}
|
||||
public InWorldToolOperationResult(final BlockState block) {
|
||||
this.blockState = block;
|
||||
this.drops = null;
|
||||
}
|
||||
|
||||
public InWorldToolOperationResult( final BlockState block )
|
||||
{
|
||||
this.blockState = block;
|
||||
this.drops = null;
|
||||
}
|
||||
public static InWorldToolOperationResult getBlockOperationResult(final ItemStack[] items) {
|
||||
final List<ItemStack> temp = new ArrayList<>();
|
||||
BlockState b = null;
|
||||
|
||||
public static InWorldToolOperationResult getBlockOperationResult( final ItemStack[] items )
|
||||
{
|
||||
final List<ItemStack> temp = new ArrayList<>();
|
||||
BlockState b = null;
|
||||
for (final ItemStack l : items) {
|
||||
if (b == null) {
|
||||
final Block bl = Block.getBlockFromItem(l.getItem());
|
||||
|
||||
for( final ItemStack l : items )
|
||||
{
|
||||
if( b == null )
|
||||
{
|
||||
final Block bl = Block.getBlockFromItem( l.getItem() );
|
||||
if (bl != null && !(bl instanceof AirBlock)) {
|
||||
b = bl.getDefaultState();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if( bl != null && !( bl instanceof AirBlock ) )
|
||||
{
|
||||
b = bl.getDefaultState();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
temp.add(l);
|
||||
}
|
||||
|
||||
temp.add( l );
|
||||
}
|
||||
return new InWorldToolOperationResult(b, temp);
|
||||
}
|
||||
|
||||
return new InWorldToolOperationResult( b, temp );
|
||||
}
|
||||
public BlockState getBlockState() {
|
||||
return this.blockState;
|
||||
}
|
||||
|
||||
public BlockState getBlockState()
|
||||
{
|
||||
return this.blockState;
|
||||
}
|
||||
|
||||
public List<ItemStack> getDrops()
|
||||
{
|
||||
return this.drops;
|
||||
}
|
||||
public List<ItemStack> getDrops() {
|
||||
return this.drops;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -33,55 +32,50 @@ import appeng.util.inv.AdaptorItemHandlerPlayerInv;
|
||||
import appeng.util.inv.IInventoryDestination;
|
||||
import appeng.util.inv.ItemSlot;
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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>
|
||||
{
|
||||
public static InventoryAdaptor getAdaptor( final TileEntity te, final Direction d )
|
||||
{
|
||||
if( te != null )
|
||||
{
|
||||
LazyOptional<IItemHandler> cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d);
|
||||
public abstract class InventoryAdaptor implements Iterable<ItemSlot> {
|
||||
public static InventoryAdaptor getAdaptor(final TileEntity te, final Direction d) {
|
||||
if (te != null) {
|
||||
LazyOptional<IItemHandler> cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d);
|
||||
|
||||
// Attempt getting an IItemHandler for the given side via caps
|
||||
if( cap.isPresent() )
|
||||
{
|
||||
return new AdaptorItemHandler( cap.orElseThrow(IllegalStateException::new) );
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// Attempt getting an IItemHandler for the given side via caps
|
||||
if (cap.isPresent()) {
|
||||
return new AdaptorItemHandler(cap.orElseThrow(IllegalStateException::new));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static InventoryAdaptor getAdaptor( final PlayerEntity te )
|
||||
{
|
||||
if( te != null )
|
||||
{
|
||||
return new AdaptorItemHandlerPlayerInv( te );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static InventoryAdaptor getAdaptor(final PlayerEntity 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();
|
||||
}
|
||||
|
||||
@@ -18,91 +18,81 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import appeng.api.config.SortDir;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class ItemSorters {
|
||||
|
||||
public class ItemSorters
|
||||
{
|
||||
private static SortDir Direction = SortDir.ASCENDING;
|
||||
|
||||
private static SortDir Direction = SortDir.ASCENDING;
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_NAME = (o1, o2) -> {
|
||||
final int cmp = Platform.getItemDisplayName(o1).getString()
|
||||
.compareToIgnoreCase(Platform.getItemDisplayName(o2).getString());
|
||||
return applyDirection(cmp);
|
||||
};
|
||||
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_NAME = ( o1, o2 ) ->
|
||||
{
|
||||
final int cmp = Platform.getItemDisplayName( o1 ).getString().compareToIgnoreCase( Platform.getItemDisplayName( o2 ).getString() );
|
||||
return applyDirection( cmp );
|
||||
};
|
||||
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_MOD = ( o1, o2 ) ->
|
||||
{
|
||||
final AEItemStack op1 = (AEItemStack) o1;
|
||||
final AEItemStack op2 = (AEItemStack) o2;
|
||||
int cmp = op1.getModID().compareToIgnoreCase( op2.getModID() );
|
||||
if (cmp == 0) {
|
||||
cmp = Platform.getItemDisplayName(o1).getString()
|
||||
.compareToIgnoreCase(Platform.getItemDisplayName(o2).getString());
|
||||
}
|
||||
|
||||
if( cmp == 0 )
|
||||
{
|
||||
cmp = Platform.getItemDisplayName( o1 ).getString().compareToIgnoreCase( Platform.getItemDisplayName( o2 ).getString() );
|
||||
}
|
||||
return applyDirection(cmp);
|
||||
};
|
||||
|
||||
return applyDirection( cmp );
|
||||
};
|
||||
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_SIZE = ( o1, o2 ) ->
|
||||
{
|
||||
final int cmp = Long.compare( o2.getStackSize(), o1.getStackSize() );
|
||||
return applyDirection( cmp );
|
||||
};
|
||||
// FIXME private static IInvTweaks api;
|
||||
|
||||
// FIXME private static IInvTweaks api;
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_INV_TWEAKS = (o1, o2) -> {
|
||||
// FIXME if( api == null )
|
||||
// FIXME {
|
||||
return CONFIG_BASED_SORT_BY_NAME.compare(o1, o2);
|
||||
// FIXME }
|
||||
|
||||
public static final Comparator<IAEItemStack> CONFIG_BASED_SORT_BY_INV_TWEAKS = ( o1, o2 ) ->
|
||||
{
|
||||
// FIXME if( api == null )
|
||||
// FIXME {
|
||||
return CONFIG_BASED_SORT_BY_NAME.compare( o1, o2 );
|
||||
// FIXME }
|
||||
// FIXME final int cmp = api.compareItems( o1.createItemStack(),
|
||||
// o2.createItemStack() );
|
||||
// FIXME return applyDirection( cmp );
|
||||
};
|
||||
|
||||
// FIXME final int cmp = api.compareItems( o1.createItemStack(), o2.createItemStack() );
|
||||
// FIXME return applyDirection( cmp );
|
||||
};
|
||||
public static void init() {
|
||||
// FIXME if( api != null )
|
||||
// FIXME {
|
||||
// FIXME return;
|
||||
// FIXME }
|
||||
|
||||
public static void init()
|
||||
{
|
||||
// FIXME if( api != null )
|
||||
// FIXME {
|
||||
// FIXME return;
|
||||
// FIXME }
|
||||
// FIXME if( Integrations.invTweaks().isEnabled() )
|
||||
// FIXME {
|
||||
// FIXME api = Integrations.invTweaks();
|
||||
// FIXME }
|
||||
// FIXME else
|
||||
// FIXME {
|
||||
// FIXME api = null;
|
||||
// FIXME }
|
||||
}
|
||||
|
||||
// FIXME if( Integrations.invTweaks().isEnabled() )
|
||||
// FIXME {
|
||||
// FIXME api = Integrations.invTweaks();
|
||||
// FIXME }
|
||||
// FIXME else
|
||||
// FIXME {
|
||||
// FIXME api = null;
|
||||
// FIXME }
|
||||
}
|
||||
private static SortDir getDirection() {
|
||||
return Direction;
|
||||
}
|
||||
|
||||
private static SortDir getDirection()
|
||||
{
|
||||
return Direction;
|
||||
}
|
||||
public static void setDirection(final SortDir direction) {
|
||||
Direction = direction;
|
||||
}
|
||||
|
||||
public static void setDirection( final SortDir direction )
|
||||
{
|
||||
Direction = direction;
|
||||
}
|
||||
|
||||
private static int applyDirection( int cmp )
|
||||
{
|
||||
if( getDirection() == SortDir.ASCENDING )
|
||||
{
|
||||
return cmp;
|
||||
}
|
||||
return -cmp;
|
||||
}
|
||||
private static int applyDirection(int cmp) {
|
||||
if (getDirection() == SortDir.ASCENDING) {
|
||||
return cmp;
|
||||
}
|
||||
return -cmp;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,27 +18,21 @@
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,29 +18,23 @@
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
+1036
-1193
File diff suppressed because it is too large
Load Diff
@@ -18,44 +18,36 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
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( node );
|
||||
}
|
||||
@Override
|
||||
public boolean contains(final Object node) {
|
||||
return this.c.contains(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,11 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.Format;
|
||||
|
||||
|
||||
/**
|
||||
* Converter class to convert a large number into a SI system.
|
||||
*
|
||||
@@ -32,93 +30,87 @@ 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 = Long.toString(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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,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
|
||||
}
|
||||
|
||||
@@ -18,34 +18,32 @@
|
||||
|
||||
package appeng.util;
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.helpers;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
@@ -27,81 +26,70 @@ import net.minecraft.nbt.CompoundNBT;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
|
||||
|
||||
/**
|
||||
* 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 )
|
||||
{
|
||||
return !that.isEmpty() && !other.isEmpty() && that.getItem() == other.getItem();
|
||||
}
|
||||
/**
|
||||
* 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) {
|
||||
return !that.isEmpty() && !other.isEmpty() && that.getItem() == other.getItem();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.getTag(), filter.getTag() );
|
||||
}
|
||||
/**
|
||||
* 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.getTag(), filter.getTag());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.getDamage() > 1 ) == ( b.getDamage() > 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
final float percentDamagedOfA = (float) a.getDamage() / a.getMaxDamage();
|
||||
final float percentDamagedOfB = (float) b.getDamage() / 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.getDamage() > 1) == (b.getDamage() > 1);
|
||||
} else {
|
||||
final float percentDamagedOfA = (float) a.getDamage() / a.getMaxDamage();
|
||||
final float percentDamagedOfB = (float) b.getDamage() / b.getMaxDamage();
|
||||
|
||||
return ( percentDamagedOfA > mode.breakPoint ) == ( percentDamagedOfB > mode.breakPoint );
|
||||
}
|
||||
}
|
||||
return (percentDamagedOfA > mode.breakPoint) == (percentDamagedOfB > mode.breakPoint);
|
||||
}
|
||||
}
|
||||
// FIXME
|
||||
// final OreReference aOR = OreHelper.INSTANCE.getOre( a ).orElse( null );
|
||||
// final OreReference bOR = OreHelper.INSTANCE.getOre( b ).orElse( null );
|
||||
@@ -111,39 +99,36 @@ public class ItemComparisonHelper
|
||||
// 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 CompoundNBT left, final CompoundNBT 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 CompoundNBT left, final CompoundNBT right) {
|
||||
if (left == right) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final boolean isLeftEmpty = left == null || left.isEmpty();
|
||||
final boolean isRightEmpty = right == null || right.isEmpty();
|
||||
final boolean isLeftEmpty = left == null || left.isEmpty();
|
||||
final boolean isRightEmpty = right == null || right.isEmpty();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,65 +18,48 @@
|
||||
|
||||
package appeng.util.helpers;
|
||||
|
||||
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
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 CraftingInventory 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 CraftingInventory 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,53 +18,44 @@
|
||||
|
||||
package appeng.util.helpers;
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -28,240 +27,200 @@ import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
|
||||
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) {
|
||||
ItemStack extracted = this.itemHandler.extractItem(slot, amount, true);
|
||||
if (extracted.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
ItemStack extracted = this.itemHandler.extractItem( slot, amount, true );
|
||||
if( extracted.isEmpty() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!destination.canInsert(extracted)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if( !destination.canInsert( extracted ) )
|
||||
{
|
||||
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))) {
|
||||
ItemStack extracted = this.itemHandler.extractItem(slot, amount, true);
|
||||
|
||||
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 ) ) )
|
||||
{
|
||||
ItemStack extracted = this.itemHandler.extractItem( slot, amount, true );
|
||||
if (extracted.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( extracted.isEmpty() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (destination != null) {
|
||||
if (!destination.canInsert(extracted)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
if( !destination.canInsert( extracted ) )
|
||||
{
|
||||
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) {
|
||||
ItemStack simulated = this.itemHandler.extractItem(slot, amount, true);
|
||||
if (simulated.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
ItemStack simulated = this.itemHandler.extractItem( slot, amount, true );
|
||||
if( simulated.isEmpty() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!destination.canInsert(simulated)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if( !destination.canInsert( simulated ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Attempt extracting it
|
||||
extracted = this.itemHandler.extractItem(slot, amount, false);
|
||||
}
|
||||
|
||||
// Attempt extracting it
|
||||
extracted = this.itemHandler.extractItem( slot, amount, false );
|
||||
}
|
||||
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;
|
||||
}
|
||||
// Attempt extracting it
|
||||
extracted = this.itemHandler.extractItem(slot, amount, true);
|
||||
|
||||
// Attempt extracting it
|
||||
extracted = this.itemHandler.extractItem( slot, amount, true );
|
||||
if (!extracted.isEmpty() && destination != null) {
|
||||
if (!destination.canInsert(extracted)) {
|
||||
extracted = ItemStack.EMPTY; // Keep on looking...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !extracted.isEmpty() && destination != null )
|
||||
{
|
||||
if( !destination.canInsert( extracted ) )
|
||||
{
|
||||
extracted = ItemStack.EMPTY; // Keep on looking...
|
||||
}
|
||||
}
|
||||
}
|
||||
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(final ItemStack itemsToAdd, final boolean simulate) {
|
||||
if (itemsToAdd.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
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++) {
|
||||
left = this.itemHandler.insertItem(slot, left, simulate);
|
||||
|
||||
for( int slot = 0; slot < this.itemHandler.getSlots(); slot++ )
|
||||
{
|
||||
left = this.itemHandler.insertItem( slot, left, simulate );
|
||||
if (left.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
if( left.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
return left;
|
||||
}
|
||||
|
||||
return left;
|
||||
}
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,58 +18,47 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.wrapper.PlayerMainInvWrapper;
|
||||
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class AdaptorItemHandlerPlayerInv extends AdaptorItemHandler {
|
||||
public AdaptorItemHandlerPlayerInv(final PlayerEntity playerInv) {
|
||||
super(new PlayerMainInvWrapper(playerInv.inventory));
|
||||
}
|
||||
|
||||
public class AdaptorItemHandlerPlayerInv extends AdaptorItemHandler
|
||||
{
|
||||
public AdaptorItemHandlerPlayerInv( final PlayerEntity 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -29,200 +28,164 @@ import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.iterators.StackToSlotIterator;
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,11 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -18,12 +18,9 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IInventoryDestination {
|
||||
|
||||
public interface IInventoryDestination
|
||||
{
|
||||
|
||||
boolean canInsert( ItemStack stack );
|
||||
boolean canInsert(ItemStack stack);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -36,171 +35,143 @@ import appeng.api.storage.data.IItemList;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -26,57 +25,49 @@ import net.minecraft.item.ItemStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
@@ -26,32 +25,26 @@ import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
public enum InvOperation
|
||||
{
|
||||
EXTRACT, INSERT, SET
|
||||
public enum InvOperation {
|
||||
EXTRACT, INSERT, SET
|
||||
}
|
||||
|
||||
@@ -18,45 +18,38 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
class ItemHandlerIterator implements Iterator<ItemSlot> {
|
||||
|
||||
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;
|
||||
ItemHandlerIterator(IItemHandler itemHandler) {
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
|
||||
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, 1, 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, 1, true).isEmpty());
|
||||
this.itemSlot.setItemStack(this.itemHandler.getStackInSlot(this.slot));
|
||||
this.itemSlot.setSlot(this.slot);
|
||||
this.slot++;
|
||||
return this.itemSlot;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
@@ -26,86 +25,71 @@ import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
public class ItemListIgnoreCrafting<T extends IAEStack<T>> implements IItemList<T> {
|
||||
|
||||
public class ItemListIgnoreCrafting<T extends IAEStack<T>> implements IItemList<T>
|
||||
{
|
||||
private final IItemList<T> target;
|
||||
|
||||
private final IItemList<T> target;
|
||||
public ItemListIgnoreCrafting(final IItemList<T> cla) {
|
||||
this.target = cla;
|
||||
}
|
||||
|
||||
public ItemListIgnoreCrafting( final IItemList<T> cla )
|
||||
{
|
||||
this.target = cla;
|
||||
}
|
||||
@Override
|
||||
public void add(T option) {
|
||||
if (option != null && option.isCraftable()) {
|
||||
option = option.copy();
|
||||
option.setCraftable(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add( T option )
|
||||
{
|
||||
if( option != null && option.isCraftable() )
|
||||
{
|
||||
option = option.copy();
|
||||
option.setCraftable( false );
|
||||
}
|
||||
this.target.add(option);
|
||||
}
|
||||
|
||||
this.target.add( option );
|
||||
}
|
||||
@Override
|
||||
public T findPrecise(final T i) {
|
||||
return this.target.findPrecise(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T findPrecise( final T i )
|
||||
{
|
||||
return this.target.findPrecise( i );
|
||||
}
|
||||
@Override
|
||||
public Collection<T> findFuzzy(final T input, final FuzzyMode fuzzy) {
|
||||
return this.target.findFuzzy(input, fuzzy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<T> findFuzzy( final T input, final FuzzyMode fuzzy )
|
||||
{
|
||||
return this.target.findFuzzy( input, fuzzy );
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.target.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return this.target.isEmpty();
|
||||
}
|
||||
@Override
|
||||
public void addStorage(final T option) {
|
||||
this.target.addStorage(option);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStorage( final T option )
|
||||
{
|
||||
this.target.addStorage( option );
|
||||
}
|
||||
@Override
|
||||
public void addCrafting(final T option) {
|
||||
// nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCrafting( final T option )
|
||||
{
|
||||
// nothing.
|
||||
}
|
||||
@Override
|
||||
public void addRequestable(final T option) {
|
||||
this.target.addRequestable(option);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequestable( final T option )
|
||||
{
|
||||
this.target.addRequestable( option );
|
||||
}
|
||||
@Override
|
||||
public T getFirstItem() {
|
||||
return this.target.getFirstItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getFirstItem()
|
||||
{
|
||||
return this.target.getFirstItem();
|
||||
}
|
||||
@Override
|
||||
public int size() {
|
||||
return this.target.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return this.target.size();
|
||||
}
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return this.target.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator()
|
||||
{
|
||||
return this.target.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetStatus()
|
||||
{
|
||||
this.target.resetStatus();
|
||||
}
|
||||
@Override
|
||||
public void resetStatus() {
|
||||
this.target.resetStatus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,63 +18,54 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -30,141 +29,118 @@ import net.minecraftforge.items.wrapper.EmptyHandler;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,26 +18,21 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class WrapperCursorItemHandler extends ItemStackHandler {
|
||||
private final PlayerInventory inv;
|
||||
|
||||
public class WrapperCursorItemHandler extends ItemStackHandler
|
||||
{
|
||||
private final PlayerInventory inv;
|
||||
public WrapperCursorItemHandler(PlayerInventory PlayerInventory) {
|
||||
super(1);
|
||||
|
||||
public WrapperCursorItemHandler( PlayerInventory PlayerInventory )
|
||||
{
|
||||
super( 1 );
|
||||
this.inv = PlayerInventory;
|
||||
this.setStackInSlot(0, PlayerInventory.getItemStack());
|
||||
}
|
||||
|
||||
this.inv = PlayerInventory;
|
||||
this.setStackInSlot( 0, PlayerInventory.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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -28,71 +27,58 @@ import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -27,97 +26,80 @@ 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 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(PlayerEntity player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer( PlayerEntity player )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void openInventory(PlayerEntity player) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory( PlayerEntity player )
|
||||
{
|
||||
// NOP
|
||||
}
|
||||
@Override
|
||||
public void closeInventory(PlayerEntity player) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory( PlayerEntity 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 void clear()
|
||||
{
|
||||
ItemHandlerUtil.clear( this.inv );
|
||||
}
|
||||
@Override
|
||||
public void clear() {
|
||||
ItemHandlerUtil.clear(this.inv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -27,94 +26,77 @@ import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -27,55 +26,45 @@ import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,32 +18,26 @@
|
||||
|
||||
package appeng.util.inv.filter;
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,47 +18,37 @@
|
||||
|
||||
package appeng.util.inv.filter;
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,11 @@
|
||||
|
||||
package appeng.util.inv.filter;
|
||||
|
||||
|
||||
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,7 +18,6 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -41,297 +40,248 @@ import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public final 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 static final String NBT_ITEMSTACK = "is";
|
||||
|
||||
public final 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 static final String NBT_ITEMSTACK = "is";
|
||||
private final AESharedItemStack sharedStack;
|
||||
|
||||
private final AESharedItemStack sharedStack;
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private ITextComponent displayName;
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private List<ITextComponent> tooltip;
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private ITextComponent displayName;
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
private List<ITextComponent> tooltip;
|
||||
private AEItemStack(final AEItemStack is) {
|
||||
this.setStackSize(is.getStackSize());
|
||||
this.setCraftable(is.isCraftable());
|
||||
this.setCountRequestable(is.getCountRequestable());
|
||||
this.sharedStack = is.sharedStack;
|
||||
}
|
||||
|
||||
private AEItemStack( final AEItemStack is )
|
||||
{
|
||||
this.setStackSize( is.getStackSize() );
|
||||
this.setCraftable( is.isCraftable() );
|
||||
this.setCountRequestable( is.getCountRequestable() );
|
||||
this.sharedStack = is.sharedStack;
|
||||
}
|
||||
private AEItemStack(final AESharedItemStack is, long size) {
|
||||
this.sharedStack = is;
|
||||
this.setStackSize(size);
|
||||
this.setCraftable(false);
|
||||
this.setCountRequestable(0);
|
||||
}
|
||||
|
||||
private AEItemStack( final AESharedItemStack is, long size )
|
||||
{
|
||||
this.sharedStack = is;
|
||||
this.setStackSize( size );
|
||||
this.setCraftable( false );
|
||||
this.setCountRequestable( 0 );
|
||||
}
|
||||
@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 CompoundNBT i) {
|
||||
if (i == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IAEItemStack fromNBT( final CompoundNBT i )
|
||||
{
|
||||
if( i == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
final ItemStack itemstack = ItemStack.read(i.getCompound(NBT_ITEMSTACK));
|
||||
if (itemstack.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final ItemStack itemstack = ItemStack.read( i.getCompound( NBT_ITEMSTACK ) );
|
||||
if( itemstack.isEmpty() )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@Override
|
||||
public void writeToNBT(final CompoundNBT i) {
|
||||
final CompoundNBT itemStack = new CompoundNBT();
|
||||
this.getDefinition().write(itemStack);
|
||||
|
||||
@Override
|
||||
public void writeToNBT( final CompoundNBT i )
|
||||
{
|
||||
final CompoundNBT itemStack = new CompoundNBT();
|
||||
this.getDefinition().write( itemStack );
|
||||
i.put(NBT_ITEMSTACK, itemStack);
|
||||
i.putLong(NBT_STACKSIZE, this.getStackSize());
|
||||
i.putLong(NBT_REQUESTABLE, this.getCountRequestable());
|
||||
i.putBoolean(NBT_CRAFTABLE, this.isCraftable());
|
||||
}
|
||||
|
||||
i.put( NBT_ITEMSTACK, itemStack );
|
||||
i.putLong( NBT_STACKSIZE, this.getStackSize() );
|
||||
i.putLong( NBT_REQUESTABLE, this.getCountRequestable() );
|
||||
i.putBoolean( NBT_CRAFTABLE, this.isCraftable() );
|
||||
}
|
||||
public static AEItemStack fromPacket(final PacketBuffer buffer) {
|
||||
final boolean isCraftable = buffer.readBoolean();
|
||||
final long stackSize = buffer.readVarLong();
|
||||
final long countRequestable = buffer.readVarLong();
|
||||
final ItemStack itemstack = buffer.readItemStack();
|
||||
|
||||
public static AEItemStack fromPacket( final PacketBuffer buffer )
|
||||
{
|
||||
final boolean isCraftable = buffer.readBoolean();
|
||||
final long stackSize = buffer.readVarLong();
|
||||
final long countRequestable = buffer.readVarLong();
|
||||
final ItemStack itemstack = buffer.readItemStack();
|
||||
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 PacketBuffer buffer) {
|
||||
buffer.writeBoolean(this.isCraftable());
|
||||
buffer.writeVarLong(this.getStackSize());
|
||||
buffer.writeVarLong(this.getCountRequestable());
|
||||
buffer.writeItemStack(getDefinition());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToPacket( final PacketBuffer buffer )
|
||||
{
|
||||
buffer.writeBoolean( this.isCraftable() );
|
||||
buffer.writeVarLong( this.getStackSize() );
|
||||
buffer.writeVarLong( this.getCountRequestable() );
|
||||
buffer.writeItemStack( getDefinition() );
|
||||
}
|
||||
@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 AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel()
|
||||
{
|
||||
return AEApi.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 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) {
|
||||
return this.isSameType((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 )
|
||||
{
|
||||
return this.isSameType( (ItemStack) ia );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getStackSize() + "x" + this.getDefinition().getItem().getRegistryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.getStackSize() + "x" + this.getDefinition().getItem().getRegistryName();
|
||||
}
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public List<ITextComponent> getToolTip() {
|
||||
if (this.tooltip == null) {
|
||||
this.tooltip = Platform.getTooltip(this.asItemStackRepresentation());
|
||||
}
|
||||
return this.tooltip;
|
||||
}
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public List<ITextComponent> getToolTip()
|
||||
{
|
||||
if( this.tooltip == null )
|
||||
{
|
||||
this.tooltip = Platform.getTooltip( this.asItemStackRepresentation() );
|
||||
}
|
||||
return this.tooltip;
|
||||
}
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public ITextComponent getDisplayName() {
|
||||
if (this.displayName == null) {
|
||||
this.displayName = Platform.getItemDisplayName(this.asItemStackRepresentation());
|
||||
}
|
||||
return this.displayName;
|
||||
}
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
if( this.displayName == null )
|
||||
{
|
||||
this.displayName = Platform.getItemDisplayName( this.asItemStackRepresentation() );
|
||||
}
|
||||
return this.displayName;
|
||||
}
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public String getModID() {
|
||||
return this.getDefinition().getItem().getRegistryName().getNamespace();
|
||||
}
|
||||
|
||||
@OnlyIn( Dist.CLIENT )
|
||||
public String getModID()
|
||||
{
|
||||
return this.getDefinition().getItem().getRegistryName().getNamespace();
|
||||
}
|
||||
@Override
|
||||
public boolean hasTagCompound() {
|
||||
return this.getDefinition().hasTag();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTagCompound()
|
||||
{
|
||||
return this.getDefinition().hasTag();
|
||||
}
|
||||
@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()) {
|
||||
if (a.getItem().isDamageable()) {
|
||||
if (mode == FuzzyMode.IGNORE_ALL) {
|
||||
return true;
|
||||
} else if (mode == FuzzyMode.PERCENT_99) {
|
||||
return (a.getDamage() > 1) == (b.getDamage() > 1);
|
||||
} else {
|
||||
final float percentDamageOfA = (float) a.getDamage() / a.getMaxDamage();
|
||||
final float percentDamageOfB = (float) b.getDamage() / b.getMaxDamage();
|
||||
|
||||
private boolean fuzzyItemStackComparison( ItemStack a, ItemStack b, FuzzyMode mode )
|
||||
{
|
||||
if( a.getItem() == b.getItem() )
|
||||
{
|
||||
if( a.getItem().isDamageable() )
|
||||
{
|
||||
if( mode == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if( mode == FuzzyMode.PERCENT_99 )
|
||||
{
|
||||
return ( a.getDamage() > 1 ) == ( b.getDamage() > 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
final float percentDamageOfA = (float) a.getDamage() / a.getMaxDamage();
|
||||
final float percentDamageOfB = (float) b.getDamage() / b.getMaxDamage();
|
||||
return (percentDamageOfA > mode.breakPoint) == (percentDamageOfB > mode.breakPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ( percentDamageOfA > mode.breakPoint ) == ( percentDamageOfB > mode.breakPoint );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
@@ -33,54 +32,43 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.util.Platform;
|
||||
|
||||
public final class AEItemStackRegistry {
|
||||
private static final WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> SERVER_REGISTRY = new WeakHashMap<>();
|
||||
private static final WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> CLIENT_REGISTRY = new WeakHashMap<>();
|
||||
|
||||
public final class AEItemStackRegistry
|
||||
{
|
||||
private static final WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> SERVER_REGISTRY = new WeakHashMap<>();
|
||||
private static final WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> CLIENT_REGISTRY = new WeakHashMap<>();
|
||||
private AEItemStackRegistry() {
|
||||
}
|
||||
|
||||
private AEItemStackRegistry()
|
||||
{
|
||||
}
|
||||
private static WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> registry() {
|
||||
if (Platform.isClient()) {
|
||||
return CLIENT_REGISTRY;
|
||||
} else {
|
||||
return SERVER_REGISTRY;
|
||||
}
|
||||
}
|
||||
|
||||
private static WeakHashMap<AESharedItemStack, WeakReference<AESharedItemStack>> registry()
|
||||
{
|
||||
if( Platform.isClient() )
|
||||
{
|
||||
return CLIENT_REGISTRY;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SERVER_REGISTRY;
|
||||
}
|
||||
}
|
||||
static synchronized AESharedItemStack getRegisteredStack(final @Nonnull ItemStack itemStack) {
|
||||
if (itemStack.isEmpty()) {
|
||||
throw new IllegalArgumentException("stack cannot be empty");
|
||||
}
|
||||
|
||||
static synchronized AESharedItemStack getRegisteredStack( final @Nonnull ItemStack itemStack )
|
||||
{
|
||||
if( itemStack.isEmpty() )
|
||||
{
|
||||
throw new IllegalArgumentException( "stack cannot be empty" );
|
||||
}
|
||||
int oldStackSize = itemStack.getCount();
|
||||
itemStack.setCount(1);
|
||||
|
||||
int oldStackSize = itemStack.getCount();
|
||||
itemStack.setCount( 1 );
|
||||
AESharedItemStack search = new AESharedItemStack(itemStack);
|
||||
WeakReference<AESharedItemStack> weak = registry().get(search);
|
||||
AESharedItemStack ret = null;
|
||||
|
||||
AESharedItemStack search = new AESharedItemStack( itemStack );
|
||||
WeakReference<AESharedItemStack> weak = registry().get( search );
|
||||
AESharedItemStack ret = null;
|
||||
if (weak != null) {
|
||||
ret = weak.get();
|
||||
}
|
||||
|
||||
if( weak != null )
|
||||
{
|
||||
ret = weak.get();
|
||||
}
|
||||
if (ret == null) {
|
||||
ret = new AESharedItemStack(itemStack.copy());
|
||||
registry().put(ret, new WeakReference<>(ret));
|
||||
}
|
||||
itemStack.setCount(oldStackSize);
|
||||
|
||||
if( ret == null )
|
||||
{
|
||||
ret = new AESharedItemStack( itemStack.copy() );
|
||||
registry().put( ret, new WeakReference<>( ret ) );
|
||||
}
|
||||
itemStack.setCount( oldStackSize );
|
||||
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
@@ -29,196 +28,159 @@ import net.minecraft.nbt.CompoundNBT;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
|
||||
final class AESharedItemStack implements Comparable<AESharedItemStack> {
|
||||
private final ItemStack itemStack;
|
||||
private final int itemId;
|
||||
private final int itemDamage;
|
||||
private final int hashCode;
|
||||
|
||||
final class AESharedItemStack implements Comparable<AESharedItemStack>
|
||||
{
|
||||
private final ItemStack itemStack;
|
||||
private final int itemId;
|
||||
private final int itemDamage;
|
||||
private final int hashCode;
|
||||
public AESharedItemStack(final ItemStack itemStack) {
|
||||
this.itemStack = itemStack;
|
||||
this.itemId = Item.getIdFromItem(itemStack.getItem());
|
||||
this.itemDamage = itemStack.getDamage();
|
||||
this.hashCode = this.makeHashCode();
|
||||
}
|
||||
|
||||
public AESharedItemStack( final ItemStack itemStack )
|
||||
{
|
||||
this.itemStack = itemStack;
|
||||
this.itemId = Item.getIdFromItem( itemStack.getItem() );
|
||||
this.itemDamage = itemStack.getDamage();
|
||||
this.hashCode = this.makeHashCode();
|
||||
}
|
||||
Bounds getBounds(final FuzzyMode fuzzy) {
|
||||
return new Bounds(this.itemStack, fuzzy);
|
||||
}
|
||||
|
||||
Bounds getBounds( final FuzzyMode fuzzy )
|
||||
{
|
||||
return new Bounds( this.itemStack, fuzzy );
|
||||
}
|
||||
ItemStack getDefinition() {
|
||||
return this.itemStack;
|
||||
}
|
||||
|
||||
ItemStack getDefinition()
|
||||
{
|
||||
return this.itemStack;
|
||||
}
|
||||
int getItemDamage() {
|
||||
return this.itemDamage;
|
||||
}
|
||||
|
||||
int getItemDamage()
|
||||
{
|
||||
return this.itemDamage;
|
||||
}
|
||||
int getItemID() {
|
||||
return this.itemId;
|
||||
}
|
||||
|
||||
int getItemID()
|
||||
{
|
||||
return this.itemId;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return this.hashCode;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (obj instanceof AESharedItemStack) {
|
||||
final AESharedItemStack other = (AESharedItemStack) obj;
|
||||
|
||||
@Override
|
||||
public boolean equals( final Object obj )
|
||||
{
|
||||
if( obj instanceof AESharedItemStack )
|
||||
{
|
||||
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");
|
||||
|
||||
Preconditions.checkState( this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1" );
|
||||
Preconditions.checkArgument( other.getDefinition().getCount() == 1, "ItemStack#getCount() has to be 1" );
|
||||
if (this.itemStack == other.itemStack) {
|
||||
return true;
|
||||
}
|
||||
return ItemStack.areItemStacksEqual(this.itemStack, other.itemStack);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if( this.itemStack == other.itemStack )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return ItemStack.areItemStacksEqual( this.itemStack, other.itemStack );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public int compareTo(final AESharedItemStack b) {
|
||||
Preconditions.checkState(this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1");
|
||||
Preconditions.checkArgument(b.getDefinition().getCount() == 1, "ItemStack#getCount() has to be 1");
|
||||
|
||||
@Override
|
||||
public int compareTo( final AESharedItemStack b )
|
||||
{
|
||||
Preconditions.checkState( this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1" );
|
||||
Preconditions.checkArgument( b.getDefinition().getCount() == 1, "ItemStack#getCount() has to be 1" );
|
||||
if (this.itemStack == b.getDefinition()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( this.itemStack == b.getDefinition() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
final int id = this.itemId - b.itemId;
|
||||
if (id != 0) {
|
||||
return id;
|
||||
}
|
||||
|
||||
final int id = this.itemId - b.itemId;
|
||||
if( id != 0 )
|
||||
{
|
||||
return id;
|
||||
}
|
||||
final int damageValue = this.itemDamage - b.itemDamage;
|
||||
if (damageValue != 0) {
|
||||
return damageValue;
|
||||
}
|
||||
|
||||
final int damageValue = this.itemDamage - b.itemDamage;
|
||||
if( damageValue != 0 )
|
||||
{
|
||||
return damageValue;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
private int makeHashCode() {
|
||||
return Objects.hash(this.itemId, this.itemDamage, this.itemStack.hasTag() ? this.itemStack.getTag() : 0);
|
||||
}
|
||||
|
||||
private int makeHashCode()
|
||||
{
|
||||
return Objects.hash( this.itemId, this.itemDamage, this.itemStack.hasTag() ? this.itemStack.getTag() : 0 );
|
||||
}
|
||||
/**
|
||||
* Creates the lower and upper bounds for a specific shared itemstack.
|
||||
*/
|
||||
public static final class Bounds {
|
||||
/**
|
||||
* Bounds enforced by {@link ItemStack#isEmpty()}
|
||||
*/
|
||||
private static final int MIN_DAMAGE_VALUE = 0;
|
||||
private static final int MAX_DAMAGE_VALUE = Short.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* Creates the lower and upper bounds for a specific shared itemstack.
|
||||
*/
|
||||
public static final class Bounds
|
||||
{
|
||||
/**
|
||||
* Bounds enforced by {@link ItemStack#isEmpty()}
|
||||
*/
|
||||
private static final int MIN_DAMAGE_VALUE = 0;
|
||||
private static final int MAX_DAMAGE_VALUE = Short.MAX_VALUE;
|
||||
private final AESharedItemStack lower;
|
||||
private final AESharedItemStack upper;
|
||||
|
||||
private final AESharedItemStack lower;
|
||||
private final AESharedItemStack upper;
|
||||
public Bounds(final ItemStack stack, final FuzzyMode fuzzy) {
|
||||
Preconditions.checkState(!stack.isEmpty(), "ItemStack#isEmpty() has to be false");
|
||||
Preconditions.checkState(stack.getCount() == 1, "ItemStack#getCount() has to be 1");
|
||||
|
||||
public Bounds( final ItemStack stack, final FuzzyMode fuzzy )
|
||||
{
|
||||
Preconditions.checkState( !stack.isEmpty(), "ItemStack#isEmpty() has to be false" );
|
||||
Preconditions.checkState( stack.getCount() == 1, "ItemStack#getCount() has to be 1" );
|
||||
final CompoundNBT tag = stack.hasTag() ? stack.getTag() : null;
|
||||
|
||||
final CompoundNBT tag = stack.hasTag() ? stack.getTag() : null;
|
||||
this.lower = this.makeLowerBound(stack, tag, fuzzy);
|
||||
this.upper = this.makeUpperBound(stack, tag, fuzzy);
|
||||
}
|
||||
|
||||
this.lower = this.makeLowerBound( stack, tag, fuzzy );
|
||||
this.upper = this.makeUpperBound( stack, tag, fuzzy );
|
||||
}
|
||||
public AESharedItemStack lower() {
|
||||
return this.lower;
|
||||
}
|
||||
|
||||
public AESharedItemStack lower()
|
||||
{
|
||||
return this.lower;
|
||||
}
|
||||
public AESharedItemStack upper() {
|
||||
return this.upper;
|
||||
}
|
||||
|
||||
public AESharedItemStack upper()
|
||||
{
|
||||
return this.upper;
|
||||
}
|
||||
private AESharedItemStack makeLowerBound(final ItemStack itemStack, final CompoundNBT tag,
|
||||
final FuzzyMode fuzzy) {
|
||||
final ItemStack newDef = itemStack.copy();
|
||||
|
||||
private AESharedItemStack makeLowerBound( final ItemStack itemStack, final CompoundNBT tag, final FuzzyMode fuzzy )
|
||||
{
|
||||
final ItemStack newDef = itemStack.copy();
|
||||
if (newDef.getItem().isDamageable()) {
|
||||
if (fuzzy == FuzzyMode.IGNORE_ALL) {
|
||||
newDef.setDamage(MIN_DAMAGE_VALUE);
|
||||
} else if (fuzzy == FuzzyMode.PERCENT_99) {
|
||||
if (itemStack.getDamage() == MIN_DAMAGE_VALUE) {
|
||||
newDef.setDamage(MIN_DAMAGE_VALUE);
|
||||
} else {
|
||||
newDef.setDamage(MIN_DAMAGE_VALUE + 1);
|
||||
}
|
||||
} else {
|
||||
final int breakpoint = fuzzy.calculateBreakPoint(itemStack.getMaxDamage());
|
||||
final int damage = breakpoint <= itemStack.getDamage() ? breakpoint : 0;
|
||||
newDef.setDamage(damage);
|
||||
}
|
||||
}
|
||||
|
||||
if( newDef.getItem().isDamageable() )
|
||||
{
|
||||
if( fuzzy == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
newDef.setDamage( MIN_DAMAGE_VALUE );
|
||||
}
|
||||
else if( fuzzy == FuzzyMode.PERCENT_99 )
|
||||
{
|
||||
if( itemStack.getDamage() == MIN_DAMAGE_VALUE )
|
||||
{
|
||||
newDef.setDamage( MIN_DAMAGE_VALUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
newDef.setDamage( MIN_DAMAGE_VALUE + 1 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final int breakpoint = fuzzy.calculateBreakPoint( itemStack.getMaxDamage() );
|
||||
final int damage = breakpoint <= itemStack.getDamage() ? breakpoint : 0;
|
||||
newDef.setDamage( damage );
|
||||
}
|
||||
}
|
||||
return new AESharedItemStack(newDef);
|
||||
}
|
||||
|
||||
return new AESharedItemStack( newDef );
|
||||
}
|
||||
private AESharedItemStack makeUpperBound(final ItemStack itemStack, final CompoundNBT tag,
|
||||
final FuzzyMode fuzzy) {
|
||||
final ItemStack newDef = itemStack.copy();
|
||||
|
||||
private AESharedItemStack makeUpperBound( final ItemStack itemStack, final CompoundNBT tag, final FuzzyMode fuzzy )
|
||||
{
|
||||
final ItemStack newDef = itemStack.copy();
|
||||
if (newDef.getItem().isDamageable()) {
|
||||
if (fuzzy == FuzzyMode.IGNORE_ALL) {
|
||||
newDef.setDamage(itemStack.getMaxDamage() + 1);
|
||||
} else if (fuzzy == FuzzyMode.PERCENT_99) {
|
||||
if (itemStack.getDamage() == MIN_DAMAGE_VALUE) {
|
||||
newDef.setDamage(MIN_DAMAGE_VALUE);
|
||||
} else {
|
||||
newDef.setDamage(itemStack.getMaxDamage() + 1);
|
||||
}
|
||||
} else {
|
||||
final int breakpoint = fuzzy.calculateBreakPoint(itemStack.getMaxDamage());
|
||||
final int damage = itemStack.getDamage() < breakpoint ? breakpoint - 1
|
||||
: itemStack.getMaxDamage() + 1;
|
||||
newDef.setDamage(damage);
|
||||
}
|
||||
}
|
||||
|
||||
if( newDef.getItem().isDamageable() )
|
||||
{
|
||||
if( fuzzy == FuzzyMode.IGNORE_ALL )
|
||||
{
|
||||
newDef.setDamage( itemStack.getMaxDamage() + 1 );
|
||||
}
|
||||
else if( fuzzy == FuzzyMode.PERCENT_99 )
|
||||
{
|
||||
if( itemStack.getDamage() == MIN_DAMAGE_VALUE )
|
||||
{
|
||||
newDef.setDamage( MIN_DAMAGE_VALUE );
|
||||
}
|
||||
else
|
||||
{
|
||||
newDef.setDamage( itemStack.getMaxDamage() + 1 );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
final int breakpoint = fuzzy.calculateBreakPoint( itemStack.getMaxDamage() );
|
||||
final int damage = itemStack.getDamage() < breakpoint ? breakpoint - 1 : itemStack.getMaxDamage() + 1;
|
||||
newDef.setDamage( damage );
|
||||
}
|
||||
}
|
||||
return new AESharedItemStack(newDef);
|
||||
}
|
||||
|
||||
return new AESharedItemStack( newDef );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,102 +18,86 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
public abstract class AEStack<T extends IAEStack<T>> implements IAEStack<T> {
|
||||
|
||||
public abstract class AEStack<T extends IAEStack<T>> implements IAEStack<T>
|
||||
{
|
||||
private boolean isCraftable;
|
||||
private long stackSize;
|
||||
private long countRequestable;
|
||||
|
||||
private boolean isCraftable;
|
||||
private long stackSize;
|
||||
private long countRequestable;
|
||||
@Override
|
||||
public long getStackSize() {
|
||||
return this.stackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getStackSize()
|
||||
{
|
||||
return this.stackSize;
|
||||
}
|
||||
@Override
|
||||
public T setStackSize(final long ss) {
|
||||
this.stackSize = ss;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T setStackSize( final long ss )
|
||||
{
|
||||
this.stackSize = ss;
|
||||
return (T) this;
|
||||
}
|
||||
@Override
|
||||
public long getCountRequestable() {
|
||||
return this.countRequestable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCountRequestable()
|
||||
{
|
||||
return this.countRequestable;
|
||||
}
|
||||
@Override
|
||||
public T setCountRequestable(final long countRequestable) {
|
||||
this.countRequestable = countRequestable;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T setCountRequestable( final long countRequestable )
|
||||
{
|
||||
this.countRequestable = countRequestable;
|
||||
return (T) this;
|
||||
}
|
||||
@Override
|
||||
public boolean isCraftable() {
|
||||
return this.isCraftable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCraftable()
|
||||
{
|
||||
return this.isCraftable;
|
||||
}
|
||||
@Override
|
||||
public T setCraftable(final boolean isCraftable) {
|
||||
this.isCraftable = isCraftable;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T setCraftable( final boolean isCraftable )
|
||||
{
|
||||
this.isCraftable = isCraftable;
|
||||
return (T) this;
|
||||
}
|
||||
@Override
|
||||
public T reset() {
|
||||
this.stackSize = 0;
|
||||
this.setCountRequestable(0);
|
||||
this.setCraftable(false);
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T reset()
|
||||
{
|
||||
this.stackSize = 0;
|
||||
this.setCountRequestable( 0 );
|
||||
this.setCraftable( false );
|
||||
return (T) this;
|
||||
}
|
||||
@Override
|
||||
public T empty() {
|
||||
final T dup = this.copy();
|
||||
dup.reset();
|
||||
return dup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T empty()
|
||||
{
|
||||
final T dup = this.copy();
|
||||
dup.reset();
|
||||
return dup;
|
||||
}
|
||||
@Override
|
||||
public boolean isMeaningful() {
|
||||
return this.stackSize != 0 || this.countRequestable > 0 || this.isCraftable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMeaningful()
|
||||
{
|
||||
return this.stackSize != 0 || this.countRequestable > 0 || this.isCraftable;
|
||||
}
|
||||
@Override
|
||||
public void incStackSize(final long i) {
|
||||
this.stackSize += i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incStackSize( final long i )
|
||||
{
|
||||
this.stackSize += i;
|
||||
}
|
||||
@Override
|
||||
public void decStackSize(final long i) {
|
||||
this.stackSize -= i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decStackSize( final long i )
|
||||
{
|
||||
this.stackSize -= i;
|
||||
}
|
||||
@Override
|
||||
public void incCountRequestable(final long i) {
|
||||
this.countRequestable += i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incCountRequestable( final long i )
|
||||
{
|
||||
this.countRequestable += i;
|
||||
}
|
||||
@Override
|
||||
public void decCountRequestable(final long i) {
|
||||
this.countRequestable -= i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decCountRequestable( final long i )
|
||||
{
|
||||
this.countRequestable -= i;
|
||||
}
|
||||
|
||||
protected abstract boolean hasTagCompound();
|
||||
protected abstract boolean hasTagCompound();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
@@ -28,173 +27,145 @@ import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
abstract class AbstractItemList implements IItemList<IAEItemStack> {
|
||||
|
||||
abstract class AbstractItemList implements IItemList<IAEItemStack>
|
||||
{
|
||||
@Override
|
||||
public void add(final IAEItemStack option) {
|
||||
if (option == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add( final IAEItemStack option )
|
||||
{
|
||||
if( option == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
final IAEItemStack st = this.getRecords().get(((AEItemStack) option).getSharedStack());
|
||||
|
||||
final IAEItemStack st = this.getRecords().get( ( (AEItemStack) option ).getSharedStack() );
|
||||
if (st != null) {
|
||||
st.add(option);
|
||||
return;
|
||||
}
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
st.add( option );
|
||||
return;
|
||||
}
|
||||
final IAEItemStack opt = option.copy();
|
||||
|
||||
final IAEItemStack opt = option.copy();
|
||||
this.putItemRecord(opt);
|
||||
}
|
||||
|
||||
this.putItemRecord( opt );
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack findPrecise(final IAEItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack findPrecise( final IAEItemStack itemStack )
|
||||
{
|
||||
if( itemStack == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return this.getRecords().get(((AEItemStack) itemStack).getSharedStack());
|
||||
}
|
||||
|
||||
return this.getRecords().get( ( (AEItemStack) itemStack ).getSharedStack() );
|
||||
}
|
||||
@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();
|
||||
}
|
||||
return this.getRecords().values();
|
||||
}
|
||||
|
||||
return this.getRecords().values();
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
@Override
|
||||
public void addStorage(final IAEItemStack option) {
|
||||
if (option == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStorage( final IAEItemStack option )
|
||||
{
|
||||
if( option == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
final IAEItemStack st = this.getRecords().get(((AEItemStack) option).getSharedStack());
|
||||
|
||||
final IAEItemStack st = this.getRecords().get( ( (AEItemStack) option ).getSharedStack() );
|
||||
if (st != null) {
|
||||
st.incStackSize(option.getStackSize());
|
||||
return;
|
||||
}
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
st.incStackSize( option.getStackSize() );
|
||||
return;
|
||||
}
|
||||
final IAEItemStack opt = option.copy();
|
||||
|
||||
final IAEItemStack opt = option.copy();
|
||||
this.putItemRecord(opt);
|
||||
}
|
||||
|
||||
this.putItemRecord( opt );
|
||||
}
|
||||
@Override
|
||||
public void addCrafting(final IAEItemStack option) {
|
||||
if (option == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCrafting( final IAEItemStack option )
|
||||
{
|
||||
if( option == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
final IAEItemStack st = this.getRecords().get(((AEItemStack) option).getSharedStack());
|
||||
|
||||
final IAEItemStack st = this.getRecords().get( ( (AEItemStack) option ).getSharedStack() );
|
||||
if (st != null) {
|
||||
st.setCraftable(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
st.setCraftable( true );
|
||||
return;
|
||||
}
|
||||
final IAEItemStack opt = option.copy();
|
||||
opt.setStackSize(0);
|
||||
opt.setCraftable(true);
|
||||
|
||||
final IAEItemStack opt = option.copy();
|
||||
opt.setStackSize( 0 );
|
||||
opt.setCraftable( true );
|
||||
this.putItemRecord(opt);
|
||||
}
|
||||
|
||||
this.putItemRecord( opt );
|
||||
}
|
||||
@Override
|
||||
public void addRequestable(final IAEItemStack option) {
|
||||
if (option == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequestable( final IAEItemStack option )
|
||||
{
|
||||
if( option == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
final IAEItemStack st = this.getRecords().get(((AEItemStack) option).getSharedStack());
|
||||
|
||||
final IAEItemStack st = this.getRecords().get( ( (AEItemStack) option ).getSharedStack() );
|
||||
if (st != null) {
|
||||
st.setCountRequestable(st.getCountRequestable() + option.getCountRequestable());
|
||||
return;
|
||||
}
|
||||
|
||||
if( st != null )
|
||||
{
|
||||
st.setCountRequestable( st.getCountRequestable() + option.getCountRequestable() );
|
||||
return;
|
||||
}
|
||||
final IAEItemStack opt = option.copy();
|
||||
opt.setStackSize(0);
|
||||
opt.setCraftable(false);
|
||||
opt.setCountRequestable(option.getCountRequestable());
|
||||
|
||||
final IAEItemStack opt = option.copy();
|
||||
opt.setStackSize( 0 );
|
||||
opt.setCraftable( false );
|
||||
opt.setCountRequestable( option.getCountRequestable() );
|
||||
this.putItemRecord(opt);
|
||||
}
|
||||
|
||||
this.putItemRecord( opt );
|
||||
}
|
||||
@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 (IAEItemStack entry : getRecords().values()) {
|
||||
if (entry.isMeaningful()) {
|
||||
size++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
int size = 0;
|
||||
for( IAEItemStack entry : getRecords().values() )
|
||||
{
|
||||
if( entry.isMeaningful() )
|
||||
{
|
||||
size++;
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
@Override
|
||||
public Iterator<IAEItemStack> iterator() {
|
||||
return new MeaningfulItemIterator<>(this.getRecords().values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IAEItemStack> iterator()
|
||||
{
|
||||
return new MeaningfulItemIterator<>( this.getRecords().values() );
|
||||
}
|
||||
@Override
|
||||
public void resetStatus() {
|
||||
for (final IAEItemStack i : this) {
|
||||
i.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetStatus()
|
||||
{
|
||||
for( final IAEItemStack i : this )
|
||||
{
|
||||
i.reset();
|
||||
}
|
||||
}
|
||||
abstract Map<AESharedItemStack, IAEItemStack> getRecords();
|
||||
|
||||
abstract Map<AESharedItemStack, IAEItemStack> getRecords();
|
||||
|
||||
private IAEItemStack putItemRecord( final IAEItemStack itemStack )
|
||||
{
|
||||
return this.getRecords().put( ( (AEItemStack) itemStack ).getSharedStack(), itemStack );
|
||||
}
|
||||
private IAEItemStack putItemRecord(final IAEItemStack itemStack) {
|
||||
return this.getRecords().put(((AEItemStack) itemStack).getSharedStack(), itemStack);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
@@ -29,34 +28,28 @@ import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AESharedItemStack.Bounds;
|
||||
|
||||
class FuzzyItemList extends AbstractItemList {
|
||||
private final NavigableMap<AESharedItemStack, IAEItemStack> records = new TreeMap<>();
|
||||
|
||||
class FuzzyItemList extends AbstractItemList
|
||||
{
|
||||
private final NavigableMap<AESharedItemStack, IAEItemStack> records = new TreeMap<>();
|
||||
@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();
|
||||
}
|
||||
return this.findFuzzyDamage(filter, fuzzy);
|
||||
}
|
||||
|
||||
return this.findFuzzyDamage( filter, fuzzy );
|
||||
}
|
||||
@Override
|
||||
Map<AESharedItemStack, IAEItemStack> getRecords() {
|
||||
return this.records;
|
||||
}
|
||||
|
||||
@Override
|
||||
Map<AESharedItemStack, IAEItemStack> getRecords()
|
||||
{
|
||||
return this.records;
|
||||
}
|
||||
private Collection<IAEItemStack> findFuzzyDamage(final IAEItemStack filter, final FuzzyMode fuzzy) {
|
||||
final AEItemStack itemStack = (AEItemStack) filter;
|
||||
final Bounds bounds = itemStack.getSharedStack().getBounds(fuzzy);
|
||||
|
||||
private Collection<IAEItemStack> findFuzzyDamage( final IAEItemStack filter, final FuzzyMode fuzzy )
|
||||
{
|
||||
final AEItemStack itemStack = (AEItemStack) filter;
|
||||
final Bounds bounds = itemStack.getSharedStack().getBounds( fuzzy );
|
||||
|
||||
return this.records.subMap( bounds.lower(), true, bounds.upper(), true ).descendingMap().values();
|
||||
}
|
||||
return this.records.subMap(bounds.lower(), true, bounds.upper(), true).descendingMap().values();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.IdentityHashMap;
|
||||
@@ -32,194 +31,155 @@ import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
public final class ItemList implements IItemList<IAEItemStack> {
|
||||
|
||||
public final class ItemList implements IItemList<IAEItemStack>
|
||||
{
|
||||
private final static IItemList<IAEItemStack> NULL_ITEMLIST = new NullItemList();
|
||||
|
||||
private final static IItemList<IAEItemStack> NULL_ITEMLIST = new NullItemList();
|
||||
private final Map<Item, IItemList<IAEItemStack>> records = new IdentityHashMap<>();
|
||||
|
||||
private final Map<Item, IItemList<IAEItemStack>> records = new IdentityHashMap<>();
|
||||
@Override
|
||||
public IAEItemStack findPrecise(final IAEItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack findPrecise( final IAEItemStack itemStack )
|
||||
{
|
||||
if( itemStack == null )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return this.getRecord(itemStack.getItem()).findPrecise(itemStack);
|
||||
}
|
||||
|
||||
return this.getRecord( itemStack.getItem() ).findPrecise( itemStack );
|
||||
}
|
||||
@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();
|
||||
}
|
||||
return this.getRecord(filter.getItem()).findFuzzy(filter, fuzzy);
|
||||
}
|
||||
|
||||
return this.getRecord( filter.getItem() ).findFuzzy( filter, fuzzy );
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
@Override
|
||||
public void add(final IAEItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add( final IAEItemStack itemStack )
|
||||
{
|
||||
if( itemStack == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.getOrCreateRecord(itemStack.getItem()).add(itemStack);
|
||||
}
|
||||
|
||||
this.getOrCreateRecord( itemStack.getItem() ).add( itemStack );
|
||||
}
|
||||
@Override
|
||||
public void addStorage(final IAEItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStorage( final IAEItemStack itemStack )
|
||||
{
|
||||
if( itemStack == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.getOrCreateRecord(itemStack.getItem()).addStorage(itemStack);
|
||||
}
|
||||
|
||||
this.getOrCreateRecord( itemStack.getItem() ).addStorage( itemStack );
|
||||
}
|
||||
@Override
|
||||
public void addCrafting(final IAEItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCrafting( final IAEItemStack itemStack )
|
||||
{
|
||||
if( itemStack == null )
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.getOrCreateRecord(itemStack.getItem()).addCrafting(itemStack);
|
||||
}
|
||||
|
||||
this.getOrCreateRecord( itemStack.getItem() ).addCrafting( itemStack );
|
||||
}
|
||||
@Override
|
||||
public void addRequestable(final IAEItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequestable( final IAEItemStack itemStack )
|
||||
{
|
||||
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 (IItemList<IAEItemStack> entry : records.values()) {
|
||||
size += entry.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
int size = 0;
|
||||
for( IItemList<IAEItemStack> entry : records.values() )
|
||||
{
|
||||
size += entry.size();
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
@Override
|
||||
public Iterator<IAEItemStack> iterator() {
|
||||
return new ChainedIterator(this.records.values().iterator());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IAEItemStack> iterator()
|
||||
{
|
||||
return new ChainedIterator( this.records.values().iterator() );
|
||||
}
|
||||
@Override
|
||||
public void resetStatus() {
|
||||
for (final IAEItemStack i : this) {
|
||||
i.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetStatus()
|
||||
{
|
||||
for( final IAEItemStack i : this )
|
||||
{
|
||||
i.reset();
|
||||
}
|
||||
}
|
||||
private IItemList<IAEItemStack> getRecord(Item item) {
|
||||
return this.records.getOrDefault(item, NULL_ITEMLIST);
|
||||
}
|
||||
|
||||
private IItemList<IAEItemStack> getRecord( Item item )
|
||||
{
|
||||
return this.records.getOrDefault( item, NULL_ITEMLIST );
|
||||
}
|
||||
private IItemList<IAEItemStack> getOrCreateRecord(Item item) {
|
||||
return this.records.computeIfAbsent(item, this::makeRecordMap);
|
||||
}
|
||||
|
||||
private IItemList<IAEItemStack> getOrCreateRecord( Item item )
|
||||
{
|
||||
return this.records.computeIfAbsent( item, this::makeRecordMap );
|
||||
}
|
||||
private IItemList<IAEItemStack> makeRecordMap(Item item) {
|
||||
if (item.isDamageable()) {
|
||||
return new FuzzyItemList();
|
||||
} else {
|
||||
return new StrictItemList();
|
||||
}
|
||||
}
|
||||
|
||||
private IItemList<IAEItemStack> makeRecordMap( Item item )
|
||||
{
|
||||
if( item.isDamageable() )
|
||||
{
|
||||
return new FuzzyItemList();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new StrictItemList();
|
||||
}
|
||||
}
|
||||
private class ChainedIterator implements Iterator<IAEItemStack> {
|
||||
|
||||
private class ChainedIterator implements Iterator<IAEItemStack>
|
||||
{
|
||||
private final Iterator<IItemList<IAEItemStack>> parent;
|
||||
private Iterator<IAEItemStack> next;
|
||||
|
||||
private final Iterator<IItemList<IAEItemStack>> parent;
|
||||
private Iterator<IAEItemStack> next;
|
||||
public ChainedIterator(Iterator<IItemList<IAEItemStack>> iterator) {
|
||||
this.parent = iterator;
|
||||
if (this.parent.hasNext()) {
|
||||
this.next = this.parent.next().iterator();
|
||||
}
|
||||
}
|
||||
|
||||
public ChainedIterator( Iterator<IItemList<IAEItemStack>> iterator )
|
||||
{
|
||||
this.parent = iterator;
|
||||
if( this.parent.hasNext() )
|
||||
{
|
||||
this.next = this.parent.next().iterator();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
while (this.next != null) {
|
||||
if (this.next.hasNext()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
while( this.next != null )
|
||||
{
|
||||
if( this.next.hasNext() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (this.parent.hasNext()) {
|
||||
this.next = this.parent.next().iterator();
|
||||
} else {
|
||||
this.next = null;
|
||||
}
|
||||
}
|
||||
|
||||
if( this.parent.hasNext() )
|
||||
{
|
||||
this.next = this.parent.next().iterator();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.next = null;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack next() {
|
||||
if (this.next == null) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack next()
|
||||
{
|
||||
if( this.next == null )
|
||||
{
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
return this.next.next();
|
||||
}
|
||||
|
||||
return this.next.next();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
@@ -27,61 +26,48 @@ import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemContainer;
|
||||
|
||||
public class ItemModList implements IItemContainer<IAEItemStack> {
|
||||
|
||||
public class ItemModList implements IItemContainer<IAEItemStack>
|
||||
{
|
||||
private final IItemContainer<IAEItemStack> backingStore;
|
||||
private final IItemContainer<IAEItemStack> overrides = AEApi.instance().storage()
|
||||
.getStorageChannel(IItemStorageChannel.class).createList();
|
||||
|
||||
private final IItemContainer<IAEItemStack> backingStore;
|
||||
private final IItemContainer<IAEItemStack> overrides = AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList();
|
||||
public ItemModList(final IItemContainer<IAEItemStack> backend) {
|
||||
this.backingStore = backend;
|
||||
}
|
||||
|
||||
public ItemModList( final IItemContainer<IAEItemStack> backend )
|
||||
{
|
||||
this.backingStore = backend;
|
||||
}
|
||||
@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 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 IAEItemStack findPrecise(final IAEItemStack i) {
|
||||
final IAEItemStack over = this.overrides.findPrecise(i);
|
||||
if (over == null) {
|
||||
return this.backingStore.findPrecise(i);
|
||||
}
|
||||
return over;
|
||||
}
|
||||
|
||||
@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 Collection<IAEItemStack> findFuzzy(final IAEItemStack input, final FuzzyMode fuzzy) {
|
||||
return this.overrides.findFuzzy(input, fuzzy);
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.overrides.isEmpty() && this.backingStore.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
@@ -26,61 +25,50 @@ import java.util.NoSuchElementException;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
public class MeaningfulItemIterator<T extends IAEItemStack> implements Iterator<T> {
|
||||
|
||||
public class MeaningfulItemIterator<T extends IAEItemStack> implements Iterator<T>
|
||||
{
|
||||
private final Collection<T> collection;
|
||||
private final Iterator<T> parent;
|
||||
private T next;
|
||||
private final Collection<T> toRemove = new ArrayList<>();
|
||||
|
||||
private final Collection<T> collection;
|
||||
private final Iterator<T> parent;
|
||||
private T next;
|
||||
private final Collection<T> toRemove = new ArrayList<>();
|
||||
public MeaningfulItemIterator(final Collection<T> collection) {
|
||||
this.collection = collection;
|
||||
this.parent = collection.iterator();
|
||||
}
|
||||
|
||||
public MeaningfulItemIterator( final Collection<T> collection )
|
||||
{
|
||||
this.collection = collection;
|
||||
this.parent = collection.iterator();
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
while (this.parent.hasNext()) {
|
||||
this.next = this.parent.next();
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
while( this.parent.hasNext() )
|
||||
{
|
||||
this.next = this.parent.next();
|
||||
if (this.next.isMeaningful()) {
|
||||
return true;
|
||||
} else {
|
||||
// TODO: Avoid if possible
|
||||
this.toRemove.add(this.next);
|
||||
// this.parent.remove(); // self cleaning :3
|
||||
}
|
||||
}
|
||||
|
||||
if( this.next.isMeaningful() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Avoid if possible
|
||||
this.toRemove.add( this.next );
|
||||
// this.parent.remove(); // self cleaning :3
|
||||
}
|
||||
}
|
||||
// Cleanup afterwards to avoid CMEs
|
||||
this.toRemove.forEach(entry -> this.collection.remove(entry));
|
||||
|
||||
// Cleanup afterwards to avoid CMEs
|
||||
this.toRemove.forEach( entry -> this.collection.remove( entry ) );
|
||||
this.next = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
this.next = null;
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public T next() {
|
||||
if (this.next == null) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next()
|
||||
{
|
||||
if( this.next == null )
|
||||
{
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
return this.next;
|
||||
}
|
||||
|
||||
return this.next;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
this.parent.remove();
|
||||
}
|
||||
@Override
|
||||
public void remove() {
|
||||
this.parent.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
@@ -27,69 +26,56 @@ import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
public class NullItemList implements IItemList<IAEItemStack> {
|
||||
|
||||
public class NullItemList implements IItemList<IAEItemStack>
|
||||
{
|
||||
@Override
|
||||
public void add(IAEItemStack option) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add( IAEItemStack option )
|
||||
{
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack findPrecise(IAEItemStack i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack findPrecise( IAEItemStack i )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Collection<IAEItemStack> findFuzzy(IAEItemStack input, FuzzyMode fuzzy) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IAEItemStack> findFuzzy( IAEItemStack input, FuzzyMode fuzzy )
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public void addStorage(IAEItemStack option) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStorage( IAEItemStack option )
|
||||
{
|
||||
}
|
||||
@Override
|
||||
public void addCrafting(IAEItemStack option) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCrafting( IAEItemStack option )
|
||||
{
|
||||
}
|
||||
@Override
|
||||
public void addRequestable(IAEItemStack option) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequestable( IAEItemStack option )
|
||||
{
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack getFirstItem() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack getFirstItem()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public Iterator<IAEItemStack> iterator() {
|
||||
return Collections.emptyIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IAEItemStack> iterator()
|
||||
{
|
||||
return Collections.emptyIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetStatus()
|
||||
{
|
||||
}
|
||||
@Override
|
||||
public void resetStatus() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,22 +18,18 @@
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
class StrictItemList extends AbstractItemList {
|
||||
|
||||
class StrictItemList extends AbstractItemList
|
||||
{
|
||||
private final Map<AESharedItemStack, IAEItemStack> records = new IdentityHashMap<>();
|
||||
|
||||
private final Map<AESharedItemStack, IAEItemStack> records = new IdentityHashMap<>();
|
||||
|
||||
@Override
|
||||
Map<AESharedItemStack, IAEItemStack> getRecords()
|
||||
{
|
||||
return this.records;
|
||||
}
|
||||
@Override
|
||||
Map<AESharedItemStack, IAEItemStack> getRecords() {
|
||||
return this.records;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,45 +18,38 @@
|
||||
|
||||
package appeng.util.iterators;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.tile.inventory.AppEngInternalAEInventory;
|
||||
|
||||
public final class AEInvIterator implements Iterator<IAEItemStack> {
|
||||
private final AppEngInternalAEInventory inventory;
|
||||
private final int size;
|
||||
|
||||
public final class AEInvIterator implements Iterator<IAEItemStack>
|
||||
{
|
||||
private final AppEngInternalAEInventory inventory;
|
||||
private final int size;
|
||||
private int counter = 0;
|
||||
|
||||
private int counter = 0;
|
||||
public AEInvIterator(final AppEngInternalAEInventory inventory) {
|
||||
this.inventory = inventory;
|
||||
this.size = this.inventory.getSlots();
|
||||
}
|
||||
|
||||
public AEInvIterator( final AppEngInternalAEInventory inventory )
|
||||
{
|
||||
this.inventory = inventory;
|
||||
this.size = this.inventory.getSlots();
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.counter < this.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return this.counter < this.size;
|
||||
}
|
||||
@Override
|
||||
public IAEItemStack next() {
|
||||
final IAEItemStack result = this.inventory.getAEStackInSlot(this.counter);
|
||||
|
||||
@Override
|
||||
public IAEItemStack next()
|
||||
{
|
||||
final IAEItemStack result = this.inventory.getAEStackInSlot( this.counter );
|
||||
this.counter++;
|
||||
|
||||
this.counter++;
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,38 +18,31 @@
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,44 +18,37 @@
|
||||
|
||||
package appeng.util.iterators;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public final class InvIterator implements Iterator<ItemStack> {
|
||||
private final IItemHandler inventory;
|
||||
private final int size;
|
||||
|
||||
public final class InvIterator implements Iterator<ItemStack>
|
||||
{
|
||||
private final IItemHandler inventory;
|
||||
private final int size;
|
||||
private int counter = 0;
|
||||
|
||||
private int counter = 0;
|
||||
public InvIterator(final IItemHandler inventory) {
|
||||
this.inventory = inventory;
|
||||
this.size = this.inventory.getSlots();
|
||||
}
|
||||
|
||||
public InvIterator( final IItemHandler inventory )
|
||||
{
|
||||
this.inventory = inventory;
|
||||
this.size = this.inventory.getSlots();
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.counter < this.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return this.counter < this.size;
|
||||
}
|
||||
@Override
|
||||
public ItemStack next() {
|
||||
final ItemStack result = this.inventory.getStackInSlot(this.counter);
|
||||
this.counter++;
|
||||
|
||||
@Override
|
||||
public ItemStack next()
|
||||
{
|
||||
final ItemStack result = this.inventory.getStackInSlot( this.counter );
|
||||
this.counter++;
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,28 +18,22 @@
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,39 +18,32 @@
|
||||
|
||||
package appeng.util.iterators;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
|
||||
public final class ProxyNodeIterator implements Iterator<IGridNode> {
|
||||
private final Iterator<IGridHost> hosts;
|
||||
|
||||
public final class ProxyNodeIterator implements Iterator<IGridNode>
|
||||
{
|
||||
private final Iterator<IGridHost> hosts;
|
||||
public ProxyNodeIterator(final Iterator<IGridHost> hosts) {
|
||||
this.hosts = hosts;
|
||||
}
|
||||
|
||||
public ProxyNodeIterator( final Iterator<IGridHost> hosts )
|
||||
{
|
||||
this.hosts = hosts;
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.hosts.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return this.hosts.hasNext();
|
||||
}
|
||||
@Override
|
||||
public IGridNode next() {
|
||||
final IGridHost host = this.hosts.next();
|
||||
return host.getGridNode(AEPartLocation.INTERNAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode next()
|
||||
{
|
||||
final IGridHost host = this.hosts.next();
|
||||
return host.getGridNode( AEPartLocation.INTERNAL );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,44 +18,37 @@
|
||||
|
||||
package appeng.util.iterators;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.util.inv.ItemSlot;
|
||||
|
||||
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.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,30 +18,24 @@
|
||||
|
||||
package appeng.util.prioritylist;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
public class DefaultPriorityList<T extends IAEStack<T>> implements IPartitionList<T> {
|
||||
|
||||
public class DefaultPriorityList<T extends IAEStack<T>> implements IPartitionList<T>
|
||||
{
|
||||
@Override
|
||||
public boolean isListed(final T input) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isListed( final T input )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> getItems()
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@Override
|
||||
public Iterable<T> getItems() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,42 +18,35 @@
|
||||
|
||||
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;
|
||||
|
||||
public class FuzzyPriorityList<T extends IAEStack<T>> implements IPartitionList<T> {
|
||||
|
||||
public class FuzzyPriorityList<T extends IAEStack<T>> implements IPartitionList<T>
|
||||
{
|
||||
private final IItemList<T> list;
|
||||
private final FuzzyMode mode;
|
||||
|
||||
private final IItemList<T> list;
|
||||
private final FuzzyMode mode;
|
||||
public FuzzyPriorityList(final IItemList<T> in, final FuzzyMode mode) {
|
||||
this.list = in;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public FuzzyPriorityList( final IItemList<T> in, final FuzzyMode mode )
|
||||
{
|
||||
this.list = in;
|
||||
this.mode = mode;
|
||||
}
|
||||
@Override
|
||||
public boolean isListed(final T input) {
|
||||
final Collection<T> out = this.list.findFuzzy(input, this.mode);
|
||||
return out != null && !out.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 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,15 +18,12 @@
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -18,67 +18,52 @@
|
||||
|
||||
package appeng.util.prioritylist;
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,36 +18,29 @@
|
||||
|
||||
package appeng.util.prioritylist;
|
||||
|
||||
|
||||
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