Utils ported
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util;
|
||||
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockUpdate implements IWorldCallable<Boolean> {
|
||||
private final BlockPos pos;
|
||||
|
||||
BlockUpdate(final BlockPos pos) {
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean call(final World world) throws Exception {
|
||||
if (world.isChunkLoaded(this.pos)) {
|
||||
world.updateNeighborsAlways(this.pos, Blocks.AIR);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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 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();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
import appeng.api.config.LevelEmitterMode;
|
||||
import appeng.api.config.Settings;
|
||||
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 ConfigManager(final IConfigManagerHost tile) {
|
||||
this.target = tile;
|
||||
}
|
||||
|
||||
@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 Enum<?> getSetting(final Settings settingName) {
|
||||
final Enum<?> oldValue = this.settings.get(settingName);
|
||||
|
||||
if (oldValue != null) {
|
||||
return oldValue;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* save all settings using config manager.
|
||||
*
|
||||
* @param tagCompound to be written to compound
|
||||
*/
|
||||
@Override
|
||||
public void writeToNBT(final CompoundTag 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 CompoundTag 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();
|
||||
}
|
||||
|
||||
final Enum<?> oldValue = this.settings.get(entry.getKey());
|
||||
|
||||
final Enum<?> newValue = Enum.valueOf(oldValue.getClass(), value);
|
||||
|
||||
this.putSetting(entry.getKey(), newValue);
|
||||
}
|
||||
} catch (final IllegalArgumentException e) {
|
||||
AELog.debug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
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.
|
||||
*/
|
||||
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);
|
||||
} else {
|
||||
ce = next(ce);
|
||||
}
|
||||
} while (!validOptions.contains(ce));
|
||||
|
||||
return ce;
|
||||
}
|
||||
|
||||
/*
|
||||
* Simple way to cycle an enum...
|
||||
*/
|
||||
public static <T extends Enum<T>> T prevEnum(final T ce) {
|
||||
T[] values = ce.getDeclaringClass().getEnumConstants();
|
||||
|
||||
int pLoc = ce.ordinal() - 1;
|
||||
if (pLoc < 0) {
|
||||
pLoc = values.length - 1;
|
||||
}
|
||||
|
||||
if (pLoc < 0 || pLoc >= values.length) {
|
||||
pLoc = 0;
|
||||
}
|
||||
|
||||
return values[pLoc];
|
||||
}
|
||||
|
||||
/*
|
||||
* Simple way to cycle an enum...
|
||||
*/
|
||||
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) {
|
||||
pLoc = 0;
|
||||
}
|
||||
|
||||
if (pLoc < 0 || pLoc >= values.length) {
|
||||
pLoc = 0;
|
||||
}
|
||||
|
||||
return values[pLoc];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package appeng.util;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import io.netty.util.concurrent.CompleteFuture;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.GenericFutureListener;
|
||||
import io.netty.util.concurrent.SucceededFuture;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.network.ClientConnection;
|
||||
import net.minecraft.network.NetworkSide;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.packet.c2s.play.ClientSettingsC2SPacket;
|
||||
import net.minecraft.server.network.ServerPlayNetworkHandler;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.network.ServerPlayerInteractionManager;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public class FakePlayer extends ServerPlayerEntity {
|
||||
private static final WeakHashMap<World, FakePlayer> FAKE_PLAYERS = new WeakHashMap<>();
|
||||
|
||||
private static final GameProfile PROFILE = new GameProfile(UUID.fromString("60C173A5-E1E6-4B87-85B1-272CE424521D"), "[AppEng2]");
|
||||
|
||||
private FakePlayer(ServerWorld world) {
|
||||
super(world.getServer(), world, PROFILE, new ServerPlayerInteractionManager(world));
|
||||
}
|
||||
|
||||
/**
|
||||
* DO NOT COPY THE PLAYER ANYWHERE!
|
||||
* It will keep the world alive, always call this method if you need it.
|
||||
*/
|
||||
public static FakePlayer getOrCreate(ServerWorld world) {
|
||||
Objects.requireNonNull(world);
|
||||
|
||||
final FakePlayer wrp = FAKE_PLAYERS.get(world);
|
||||
if (wrp != null) {
|
||||
return wrp;
|
||||
}
|
||||
|
||||
FakePlayer p = new FakePlayer(world);
|
||||
FAKE_PLAYERS.put(world, p);
|
||||
return p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
}
|
||||
|
||||
// FIXME: We should probably find and override all methods that access the networkHandler
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util;
|
||||
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.util.IConfigManager;
|
||||
|
||||
public interface IConfigManagerHost {
|
||||
|
||||
void updateSetting(IConfigManager manager, Settings settingName, Enum<?> newValue);
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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.
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
|
||||
/**
|
||||
* Limits a number converter to a char width of at max 4 characters
|
||||
*
|
||||
* @author thatsIch
|
||||
* @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);
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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.
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.AirBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.fluid.Fluid;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class InWorldToolOperationResult {
|
||||
|
||||
private final BlockState blockState;
|
||||
private final Fluid fluid;
|
||||
private final List<ItemStack> drops;
|
||||
|
||||
public InWorldToolOperationResult() {
|
||||
this.blockState = null;
|
||||
this.drops = null;
|
||||
this.fluid = null;
|
||||
}
|
||||
|
||||
public InWorldToolOperationResult(final BlockState block, final List<ItemStack> drops) {
|
||||
this.blockState = block;
|
||||
this.fluid = null;
|
||||
this.drops = drops;
|
||||
}
|
||||
|
||||
public InWorldToolOperationResult(final BlockState block) {
|
||||
this.blockState = block;
|
||||
this.drops = null;
|
||||
this.fluid = null;
|
||||
}
|
||||
|
||||
public InWorldToolOperationResult(final BlockState block, Fluid fluid) {
|
||||
this.blockState = block;
|
||||
this.drops = null;
|
||||
this.fluid = fluid;
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
if (bl != null && !(bl instanceof AirBlock)) {
|
||||
b = bl.getDefaultState();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
temp.add(l);
|
||||
}
|
||||
|
||||
return new InWorldToolOperationResult(b, temp);
|
||||
}
|
||||
|
||||
public Fluid getFluid() {
|
||||
return fluid;
|
||||
}
|
||||
|
||||
public BlockState getBlockState() {
|
||||
return this.blockState;
|
||||
}
|
||||
|
||||
public List<ItemStack> getDrops() {
|
||||
return this.drops;
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util;
|
||||
|
||||
import alexiil.mc.lib.attributes.SearchOptions;
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
import alexiil.mc.lib.attributes.item.ItemAttributes;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.inv.AdaptorFixedInv;
|
||||
import appeng.util.inv.AdaptorItemHandlerPlayerInv;
|
||||
import appeng.util.inv.IInventoryDestination;
|
||||
import appeng.util.inv.ItemSlot;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
||||
/**
|
||||
* 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 BlockEntity te, final Direction d) {
|
||||
|
||||
FixedItemInv inv = ItemAttributes.FIXED_INV.get(te.getWorld(), te.getPos().offset(d), SearchOptions.inDirection(d.getOpposite()));
|
||||
|
||||
if (inv == ItemAttributes.FIXED_INV.defaultValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new AdaptorFixedInv(inv);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
public abstract ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode,
|
||||
IInventoryDestination destination);
|
||||
|
||||
// return what isn't used...
|
||||
public abstract ItemStack addItems(ItemStack toBeAdded);
|
||||
|
||||
public abstract ItemStack simulateAdd(ItemStack toBeSimulated);
|
||||
|
||||
public abstract boolean containsItems();
|
||||
|
||||
public abstract boolean hasSlots();
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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 {
|
||||
|
||||
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_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());
|
||||
}
|
||||
|
||||
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);
|
||||
};
|
||||
|
||||
private static SortDir getDirection() {
|
||||
return Direction;
|
||||
}
|
||||
|
||||
public static void setDirection(final SortDir direction) {
|
||||
Direction = direction;
|
||||
}
|
||||
|
||||
private static int applyDirection(int cmp) {
|
||||
if (getDirection() == SortDir.ASCENDING) {
|
||||
return cmp;
|
||||
}
|
||||
return -cmp;
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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 Lazy(final Supplier<T> supplier) {
|
||||
this.supplier = supplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() {
|
||||
if (this.instance == null) {
|
||||
this.instance = this.supplier.get();
|
||||
}
|
||||
return this.instance;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util;
|
||||
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class LookDirection {
|
||||
|
||||
private final Vec3d a;
|
||||
private final Vec3d b;
|
||||
|
||||
public LookDirection(final Vec3d a, final Vec3d b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public Vec3d getA() {
|
||||
return this.a;
|
||||
}
|
||||
|
||||
public Vec3d getB() {
|
||||
return this.b;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.api.util.IReadOnlyCollection;
|
||||
|
||||
public class ReadOnlyCollection<T> implements IReadOnlyCollection<T> {
|
||||
|
||||
private final Collection<T> c;
|
||||
|
||||
public ReadOnlyCollection(final Collection<T> in) {
|
||||
this.c = in;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return this.c.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return this.c.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.c.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(final Object node) {
|
||||
return this.c.contains(node);
|
||||
}
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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.
|
||||
*
|
||||
* @author thatsIch
|
||||
* @version rv2
|
||||
* @since rv2
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* String representation of the sorted postfixes
|
||||
*/
|
||||
private static final char[] ENCODED_POSTFIXES = "KMGTPE".toCharArray();
|
||||
|
||||
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);
|
||||
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
// 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 = "";
|
||||
|
||||
while (numberSize > width) {
|
||||
last = base;
|
||||
base /= DIVISION_BASE;
|
||||
|
||||
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 slimResult = (withPrecision.length() <= width) ? withPrecision : withoutPrecision;
|
||||
|
||||
// post condition
|
||||
assert slimResult.length() <= width;
|
||||
|
||||
return slimResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toWideReadableForm(final long number) {
|
||||
return this.toReadableFormRestrictedByWidth(number, 4);
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util;
|
||||
|
||||
public enum SettingsFrom {
|
||||
// moved the item, and replaced it.
|
||||
DISMANTLE_ITEM,
|
||||
|
||||
// used memory card?
|
||||
MEMORY_CARD
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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}";
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.helpers;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
|
||||
/**
|
||||
* A helper class for comparing {@link Item}, {@link ItemStack} or NBT
|
||||
*
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
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 );
|
||||
//
|
||||
// if( OreHelper.INSTANCE.sameOre( aOR, bOR ) )
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
|
||||
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 CompoundTag left, final CompoundTag right) {
|
||||
if (left == right) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final boolean isLeftEmpty = left == null || left.isEmpty();
|
||||
final boolean isRightEmpty = right == null || right.isEmpty();
|
||||
|
||||
if (isLeftEmpty && isRightEmpty) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isLeftEmpty != isRightEmpty) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (left != null) {
|
||||
return left.equals(right);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.helpers;
|
||||
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class ItemHandlerUtil {
|
||||
private ItemHandlerUtil() {
|
||||
}
|
||||
|
||||
public static void setStackInSlot(final FixedItemInv inv, final int slot, final ItemStack stack) {
|
||||
inv.forceSetInvStack(slot, stack);
|
||||
}
|
||||
|
||||
public static void clear(final FixedItemInv inv) {
|
||||
for (int x = 0; x < inv.getSlotCount(); x++) {
|
||||
setStackInSlot(inv, x, ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEmpty(final FixedItemInv inv) {
|
||||
for (int x = 0; x < inv.getSlotCount(); x++) {
|
||||
if (!inv.getInvStack(x).isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void copy(final FixedItemInv from, final FixedItemInv to, boolean deepCopy) {
|
||||
for (int i = 0; i < Math.min(from.getSlotCount(), to.getSlotCount()); ++i) {
|
||||
setStackInSlot(to, i, deepCopy ? from.getInvStack(i).copy() : from.getInvStack(i));
|
||||
}
|
||||
}
|
||||
|
||||
public static void copy(final CraftingInventory from, final FixedItemInv to, boolean deepCopy) {
|
||||
for (int i = 0; i < Math.min(from.size(), to.getSlotCount()); ++i) {
|
||||
setStackInSlot(to, i, deepCopy ? from.getStack(i).copy() : from.getStack(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.helpers;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import appeng.api.util.AEColor;
|
||||
|
||||
public class P2PHelper {
|
||||
|
||||
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;
|
||||
|
||||
colors[i] = AEColor.values()[nibble];
|
||||
}
|
||||
|
||||
return colors;
|
||||
}
|
||||
|
||||
public short fromColors(AEColor[] colors) {
|
||||
Preconditions.checkArgument(colors.length == 4);
|
||||
|
||||
int t = 0;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int code = colors[3 - i].ordinal() << 4 * i;
|
||||
|
||||
t |= code;
|
||||
}
|
||||
|
||||
return (short) (t & 0xFFFF);
|
||||
}
|
||||
|
||||
public String toHexDigit(AEColor color) {
|
||||
return String.format("%01X", color.ordinal());
|
||||
}
|
||||
|
||||
public String toHexString(short frequency) {
|
||||
return String.format("%04X", frequency);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
import alexiil.mc.lib.attributes.Simulation;
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
import alexiil.mc.lib.attributes.item.ItemTransferable;
|
||||
import alexiil.mc.lib.attributes.item.filter.ItemFilter;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class AdaptorFixedInv extends InventoryAdaptor {
|
||||
protected final FixedItemInv itemHandler;
|
||||
protected final ItemTransferable transferable;
|
||||
|
||||
public AdaptorFixedInv(FixedItemInv itemHandler) {
|
||||
this.itemHandler = itemHandler;
|
||||
this.transferable = itemHandler.getTransferable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSlots() {
|
||||
return this.itemHandler.getSlotCount() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems(int amount, ItemStack filter, IInventoryDestination destination) {
|
||||
ItemFilter itemFilter = createExactFilter(filter, destination);
|
||||
|
||||
return this.transferable.attemptExtraction(itemFilter, amount, Simulation.ACTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove(int amount, ItemStack filter, IInventoryDestination destination) {
|
||||
ItemFilter itemFilter = createExactFilter(filter, destination);
|
||||
|
||||
return this.transferable.attemptExtraction(itemFilter, amount, Simulation.SIMULATE);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ItemFilter createExactFilter(ItemStack filter, IInventoryDestination destination) {
|
||||
ItemFilter itemFilter = destination != null ? destination::canInsert : stack -> true;
|
||||
if (!filter.isEmpty()) {
|
||||
if (destination != null) {
|
||||
itemFilter = stack -> Platform.itemComparisons().isSameItem(stack, filter) && destination.canInsert(stack);
|
||||
} else {
|
||||
itemFilter = stack -> Platform.itemComparisons().isSameItem(stack, filter);
|
||||
}
|
||||
}
|
||||
return itemFilter;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ItemFilter createFuzzyFilter(ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination) {
|
||||
ItemFilter itemFilter = destination != null ? destination::canInsert : stack -> true;
|
||||
if (!filter.isEmpty()) {
|
||||
if (destination != null) {
|
||||
itemFilter = stack -> Platform.itemComparisons().isFuzzyEqualItem(stack, filter, fuzzyMode) && destination.canInsert(stack);
|
||||
} else {
|
||||
itemFilter = stack -> Platform.itemComparisons().isFuzzyEqualItem(stack, filter, fuzzyMode);
|
||||
}
|
||||
}
|
||||
return itemFilter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
ItemFilter itemFilter = createFuzzyFilter(filter, fuzzyMode, destination);
|
||||
|
||||
return this.transferable.attemptExtraction(itemFilter, amount, Simulation.ACTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode,
|
||||
IInventoryDestination destination) {
|
||||
ItemFilter itemFilter = createFuzzyFilter(filter, fuzzyMode, destination);
|
||||
|
||||
return this.transferable.attemptExtraction(itemFilter, amount, Simulation.SIMULATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack toBeAdded) {
|
||||
return this.addItems(toBeAdded, false);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
return this.transferable.attemptInsertion(itemsToAdd, simulate ? Simulation.SIMULATE : Simulation.ACTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems() {
|
||||
return !transferable.attemptAnyExtraction(1, Simulation.SIMULATE).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator() {
|
||||
return new ItemHandlerIterator(this.itemHandler);
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
import alexiil.mc.lib.attributes.Simulation;
|
||||
import alexiil.mc.lib.attributes.item.compat.FixedInventoryVanillaWrapper;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class AdaptorItemHandlerPlayerInv extends AdaptorFixedInv {
|
||||
|
||||
public AdaptorItemHandlerPlayerInv(final PlayerEntity playerInv) {
|
||||
super(new FixedInventoryVanillaWrapper(playerInv.inventory));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to fill existing stacks first
|
||||
*/
|
||||
@Override
|
||||
protected ItemStack addItems(final ItemStack itemsToAdd, final boolean simulate) {
|
||||
if (itemsToAdd.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
Simulation sim = simulate ? Simulation.SIMULATE : Simulation.ACTION;
|
||||
|
||||
ItemStack left = itemsToAdd.copy();
|
||||
|
||||
// First try filling slots
|
||||
for (int slot = 0; slot < this.itemHandler.getSlotCount(); slot++) {
|
||||
ItemStack is = this.itemHandler.getInvStack(slot);
|
||||
|
||||
if (Platform.itemComparisons().isSameItem(is, left)) {
|
||||
left = itemHandler.getSlot(slot).attemptInsertion(left, sim);
|
||||
}
|
||||
if (left.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
return transferable.attemptInsertion(left, sim);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,191 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.iterators.StackToSlotIterator;
|
||||
|
||||
public class AdaptorList extends InventoryAdaptor {
|
||||
|
||||
private final List<ItemStack> i;
|
||||
|
||||
public AdaptorList(final List<ItemStack> s) {
|
||||
this.i = s;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
if (amount > 0) {
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount(amount);
|
||||
is.increment(-amount);
|
||||
|
||||
// remove it..
|
||||
if (is.getCount() <= 0) {
|
||||
this.i.remove(x);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (amount > 0) {
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount(amount);
|
||||
is.increment(-amount);
|
||||
|
||||
// remove it..
|
||||
if (is.getCount() <= 0) {
|
||||
this.i.remove(x);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
final ItemStack left = toBeAdded.copy();
|
||||
|
||||
for (final ItemStack is : this.i) {
|
||||
if (ItemStack.areItemsEqual(is, left)) {
|
||||
is.increment(left.getCount());
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
this.i.add(left);
|
||||
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 Iterator<ItemSlot> iterator() {
|
||||
return new StackToSlotIterator(this.i.iterator());
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IAEAppEngInventory {
|
||||
void saveChanges();
|
||||
|
||||
void onChangeInventory(FixedItemInv inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IInventoryDestination {
|
||||
|
||||
boolean canInsert(ItemStack stack);
|
||||
}
|
||||
@@ -1,177 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class IMEAdaptor extends InventoryAdaptor {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSlots() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
if (filter.isEmpty()) {
|
||||
final IItemList<IAEItemStack> list = this.getList();
|
||||
if (!list.isEmpty()) {
|
||||
req = list.getFirstItem();
|
||||
}
|
||||
} else {
|
||||
req = AEItemStack.fromItemStack(filter);
|
||||
}
|
||||
|
||||
IAEItemStack out = null;
|
||||
|
||||
if (req != null) {
|
||||
req.setStackSize(amount);
|
||||
out = this.target.extractItems(req, type, this.src);
|
||||
}
|
||||
|
||||
if (out != null) {
|
||||
return out.createItemStack();
|
||||
}
|
||||
|
||||
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 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;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 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 boolean containsItems() {
|
||||
return !this.getList().isEmpty();
|
||||
}
|
||||
|
||||
int getMaxSlots() {
|
||||
return this.maxSlots;
|
||||
}
|
||||
|
||||
void setMaxSlots(final int maxSlots) {
|
||||
this.maxSlots = maxSlots;
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
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;
|
||||
|
||||
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 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.hasNext) {
|
||||
final IAEItemStack item = this.stack.next();
|
||||
this.slot.setAEItemStack(item);
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
this.slot.setItemStack(ItemStack.EMPTY);
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class IMEInventoryDestination implements IInventoryDestination {
|
||||
|
||||
private final IMEInventory<IAEItemStack> me;
|
||||
|
||||
public IMEInventoryDestination(final IMEInventory<IAEItemStack> o) {
|
||||
this.me = o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(final ItemStack stack) {
|
||||
|
||||
if (stack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final IAEItemStack failed = this.me.injectItems(AEItemStack.fromItemStack(stack), Actionable.SIMULATE, null);
|
||||
|
||||
if (failed == null) {
|
||||
return true;
|
||||
}
|
||||
return failed.getStackSize() != stack.getCount();
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
public enum InvOperation {
|
||||
EXTRACT, INSERT, SET
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import alexiil.mc.lib.attributes.Simulation;
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
|
||||
class ItemHandlerIterator implements Iterator<ItemSlot> {
|
||||
|
||||
private final FixedItemInv itemHandler;
|
||||
|
||||
private final ItemSlot itemSlot = new ItemSlot();
|
||||
|
||||
private int slot = 0;
|
||||
|
||||
ItemHandlerIterator(FixedItemInv itemHandler) {
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.slot < this.itemHandler.getSlotCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemSlot next() {
|
||||
if (this.slot >= this.itemHandler.getSlotCount()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
this.itemSlot.setExtractable(!this.itemHandler.getSlot(this.slot).attemptAnyExtraction(1, Simulation.SIMULATE).isEmpty());
|
||||
this.itemSlot.setItemStack(this.itemHandler.getInvStack(this.slot));
|
||||
this.itemSlot.setSlot(this.slot);
|
||||
this.slot++;
|
||||
return this.itemSlot;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
public class ItemListIgnoreCrafting<T extends IAEStack<T>> implements IItemList<T> {
|
||||
|
||||
private final IItemList<T> target;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
this.target.add(option);
|
||||
}
|
||||
|
||||
@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 boolean isEmpty() {
|
||||
return this.target.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStorage(final T option) {
|
||||
this.target.addStorage(option);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCrafting(final T option) {
|
||||
// nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequestable(final T option) {
|
||||
this.target.addRequestable(option);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getFirstItem() {
|
||||
return this.target.getFirstItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return this.target.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return this.target.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetStatus() {
|
||||
this.target.resetStatus();
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class ItemSlot {
|
||||
|
||||
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 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;
|
||||
}
|
||||
|
||||
void setAEItemStack(final IAEItemStack is) {
|
||||
this.aeItemStack = is;
|
||||
this.itemStack = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
public boolean isExtractable() {
|
||||
return this.isExtractable;
|
||||
}
|
||||
|
||||
void setExtractable(final boolean isExtractable) {
|
||||
this.isExtractable = isExtractable;
|
||||
}
|
||||
|
||||
public int getSlot() {
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
public void setSlot(final int slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
import alexiil.mc.lib.attributes.item.impl.CombinedFixedItemInv;
|
||||
import alexiil.mc.lib.attributes.item.impl.DelegatingFixedItemInv;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
// FIXME could be replaced by CombinedFixedItemInv directly
|
||||
public class WrapperChainedItemHandler extends DelegatingFixedItemInv {
|
||||
|
||||
public WrapperChainedItemHandler(FixedItemInv... itemHandler) {
|
||||
super(CombinedFixedItemInv.create(Arrays.asList(itemHandler)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
import alexiil.mc.lib.attributes.item.compat.FixedInventoryVanillaWrapper;
|
||||
import alexiil.mc.lib.attributes.item.impl.DelegatingFixedItemInv;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
|
||||
public class WrapperCursorItemHandler extends DelegatingFixedItemInv {
|
||||
|
||||
public WrapperCursorItemHandler(PlayerInventory inventory) {
|
||||
super(new FixedInventoryVanillaWrapper(inventory).getSubInv(0, 1));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import alexiil.mc.lib.attributes.ListenerRemovalToken;
|
||||
import alexiil.mc.lib.attributes.ListenerToken;
|
||||
import alexiil.mc.lib.attributes.Simulation;
|
||||
import alexiil.mc.lib.attributes.item.InvMarkDirtyListener;
|
||||
import alexiil.mc.lib.attributes.item.filter.ItemFilter;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
|
||||
// FIXME: Needs to be double checked, LBA has better ways of doing this
|
||||
public class WrapperFilteredItemHandler implements FixedItemInv {
|
||||
private final FixedItemInv handler;
|
||||
private final IAEItemFilter filter;
|
||||
|
||||
public WrapperFilteredItemHandler(@Nonnull FixedItemInv handler, @Nonnull IAEItemFilter filter) {
|
||||
this.handler = handler;
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getInvStack(int slot) {
|
||||
return this.handler.getInvStack(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setInvStack(int slot, ItemStack to, Simulation simulation) {
|
||||
return this.handler.setInvStack(slot, to, simulation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotCount() {
|
||||
return this.handler.getSlotCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
return filter.allowInsert(handler, slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemFilter getFilterForSlot(int slot) {
|
||||
return stack -> filter.allowInsert(handler, slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChangeValue() {
|
||||
return this.handler.getChangeValue();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ListenerToken addListener(InvMarkDirtyListener listener, ListenerRemovalToken removalToken) {
|
||||
return this.handler.addListener(listener, removalToken);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
import alexiil.mc.lib.attributes.item.compat.InventoryFixedWrapper;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
|
||||
public class WrapperInvItemHandler extends InventoryFixedWrapper {
|
||||
|
||||
public WrapperInvItemHandler(final FixedItemInv inv) {
|
||||
super(inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlayerUse(PlayerEntity player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import alexiil.mc.lib.attributes.ListenerRemovalToken;
|
||||
import alexiil.mc.lib.attributes.ListenerToken;
|
||||
import alexiil.mc.lib.attributes.Simulation;
|
||||
import alexiil.mc.lib.attributes.item.GroupedItemInv;
|
||||
import alexiil.mc.lib.attributes.item.InvMarkDirtyListener;
|
||||
import alexiil.mc.lib.attributes.item.impl.DelegatingGroupedItemInv;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class WrapperSupplierItemHandler implements FixedItemInv {
|
||||
private final Supplier<FixedItemInv> sourceHandler;
|
||||
|
||||
public WrapperSupplierItemHandler(Supplier<FixedItemInv> source) {
|
||||
this.sourceHandler = source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GroupedItemInv getGroupedInv() {
|
||||
return new DelegatingGroupedItemInv(this.sourceHandler.get().getGroupedInv());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getInvStack(int slot) {
|
||||
return this.sourceHandler.get().getInvStack(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setInvStack(int slot, ItemStack to, Simulation simulation) {
|
||||
return this.sourceHandler.get().setInvStack(slot, to, simulation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotCount() {
|
||||
return this.sourceHandler.get().getSlotCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
return this.sourceHandler.get().isItemValidForSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChangeValue() {
|
||||
return this.sourceHandler.get().getChangeValue();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ListenerToken addListener(InvMarkDirtyListener listener, ListenerRemovalToken removalToken) {
|
||||
return this.sourceHandler.get().addListener(listener, removalToken);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv.filter;
|
||||
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
|
||||
public class AEItemDefinitionFilter implements IAEItemFilter {
|
||||
private final IItemDefinition definition;
|
||||
|
||||
public AEItemDefinitionFilter(IItemDefinition definition) {
|
||||
this.definition = definition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowExtract(FixedItemInv inv, int slot, int amount) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert(FixedItemInv inv, int slot, ItemStack stack) {
|
||||
return this.definition.isSameAs(stack);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv.filter;
|
||||
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class AEItemFilters {
|
||||
public static final IAEItemFilter INSERT_ONLY = new InsertOnlyFilter();
|
||||
public static final IAEItemFilter EXTRACT_ONLY = new ExtractOnlyFilter();
|
||||
|
||||
private AEItemFilters() {
|
||||
}
|
||||
|
||||
private static class InsertOnlyFilter implements IAEItemFilter {
|
||||
@Override
|
||||
public boolean allowExtract(FixedItemInv inv, int slot, int amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert(FixedItemInv inv, int slot, ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ExtractOnlyFilter implements IAEItemFilter {
|
||||
@Override
|
||||
public boolean allowExtract(FixedItemInv inv, int slot, int amount) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert(FixedItemInv inv, int slot, ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv.filter;
|
||||
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IAEItemFilter {
|
||||
boolean allowExtract(FixedItemInv inv, int slot, int amount);
|
||||
|
||||
boolean allowInsert(FixedItemInv inv, int slot, ItemStack stack);
|
||||
}
|
||||
@@ -1,287 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2020, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.text.Text;
|
||||
import net.fabricmc.api.EnvType;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.IStorageChannel;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
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;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private Text displayName;
|
||||
@Environment(EnvType.CLIENT)
|
||||
private List<Text> 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 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;
|
||||
}
|
||||
|
||||
return new AEItemStack(AEItemStackRegistry.getRegisteredStack(stack), stack.getCount());
|
||||
}
|
||||
|
||||
public static IAEItemStack fromNBT(final CompoundTag i) {
|
||||
if (i == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final ItemStack itemstack = ItemStack.fromTag(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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(final CompoundTag i) {
|
||||
final CompoundTag itemStack = new CompoundTag();
|
||||
this.getDefinition().toTag(itemStack);
|
||||
|
||||
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 PacketByteBuf 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;
|
||||
}
|
||||
|
||||
final AEItemStack item = new AEItemStack(AEItemStackRegistry.getRegisteredStack(itemstack), stackSize);
|
||||
item.setCountRequestable(countRequestable);
|
||||
item.setCraftable(isCraftable);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToPacket(final PacketByteBuf 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;
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
return this.fuzzyItemStackComparison(itemStack, otherStack, mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack copy() {
|
||||
return new AEItemStack(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItem() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFluid() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IStorageChannel<IAEItemStack> getChannel() {
|
||||
return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack createItemStack() {
|
||||
return Platform.copyStackWithSize(this.getDefinition(),
|
||||
(int) Math.min(Integer.MAX_VALUE, this.getStackSize()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item getItem() {
|
||||
return this.getDefinition().getItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemDamage() {
|
||||
return this.sharedStack.getItemDamage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameType(final IAEItemStack otherStack) {
|
||||
if (otherStack == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Objects.equals(this.sharedStack, ((AEItemStack) otherStack).sharedStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameType(final ItemStack otherStack) {
|
||||
if (otherStack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
int oldSize = otherStack.getCount();
|
||||
|
||||
otherStack.setCount(1);
|
||||
boolean ret = ItemStack.areEqual(this.getDefinition(), otherStack);
|
||||
otherStack.setCount(oldSize);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@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 String toString() {
|
||||
return this.getStackSize() + "x" + Registry.ITEM.getId(this.getDefinition().getItem());
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public List<Text> getToolTip() {
|
||||
if (this.tooltip == null) {
|
||||
this.tooltip = Platform.getTooltip(this.asItemStackRepresentation());
|
||||
}
|
||||
return this.tooltip;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public Text getDisplayName() {
|
||||
if (this.displayName == null) {
|
||||
this.displayName = Platform.getItemDisplayName(this.asItemStackRepresentation());
|
||||
}
|
||||
return this.displayName;
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public String getModID() {
|
||||
return Registry.ITEM.getId(this.getDefinition().getItem()).getNamespace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasTagCompound() {
|
||||
return this.getDefinition().hasTag();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack asItemStackRepresentation() {
|
||||
return this.getDefinition().copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getDefinition() {
|
||||
return this.sharedStack.getDefinition();
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
return (percentDamageOfA > mode.breakPoint) == (percentDamageOfB > mode.breakPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 AlgorithmX2
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
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<>();
|
||||
|
||||
private AEItemStackRegistry() {
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
int oldStackSize = itemStack.getCount();
|
||||
itemStack.setCount(1);
|
||||
|
||||
AESharedItemStack search = new AESharedItemStack(itemStack);
|
||||
WeakReference<AESharedItemStack> weak = registry().get(search);
|
||||
AESharedItemStack ret = null;
|
||||
|
||||
if (weak != null) {
|
||||
ret = weak.get();
|
||||
}
|
||||
|
||||
if (ret == null) {
|
||||
ret = new AESharedItemStack(itemStack.copy());
|
||||
registry().put(ret, new WeakReference<>(ret));
|
||||
}
|
||||
itemStack.setCount(oldStackSize);
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
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;
|
||||
|
||||
public AESharedItemStack(final ItemStack itemStack) {
|
||||
this.itemStack = itemStack;
|
||||
this.itemId = Item.getRawId(itemStack.getItem());
|
||||
this.itemDamage = itemStack.getDamage();
|
||||
this.hashCode = this.makeHashCode();
|
||||
}
|
||||
|
||||
Bounds getBounds(final FuzzyMode fuzzy) {
|
||||
return new Bounds(this.itemStack, fuzzy);
|
||||
}
|
||||
|
||||
ItemStack getDefinition() {
|
||||
return this.itemStack;
|
||||
}
|
||||
|
||||
int getItemDamage() {
|
||||
return this.itemDamage;
|
||||
}
|
||||
|
||||
int getItemID() {
|
||||
return this.itemId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.hashCode;
|
||||
}
|
||||
|
||||
@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");
|
||||
|
||||
if (this.itemStack == other.itemStack) {
|
||||
return true;
|
||||
}
|
||||
return ItemStack.areEqual(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");
|
||||
|
||||
if (this.itemStack == b.getDefinition()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
final int id = this.itemId - b.itemId;
|
||||
if (id != 0) {
|
||||
return id;
|
||||
}
|
||||
|
||||
final int damageValue = this.itemDamage - b.itemDamage;
|
||||
if (damageValue != 0) {
|
||||
return damageValue;
|
||||
}
|
||||
|
||||
return 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;
|
||||
|
||||
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");
|
||||
|
||||
final CompoundTag tag = stack.hasTag() ? stack.getTag() : null;
|
||||
|
||||
this.lower = this.makeLowerBound(stack, tag, fuzzy);
|
||||
this.upper = this.makeUpperBound(stack, tag, fuzzy);
|
||||
}
|
||||
|
||||
public AESharedItemStack lower() {
|
||||
return this.lower;
|
||||
}
|
||||
|
||||
public AESharedItemStack upper() {
|
||||
return this.upper;
|
||||
}
|
||||
|
||||
private AESharedItemStack makeLowerBound(final ItemStack itemStack, final CompoundTag 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);
|
||||
}
|
||||
}
|
||||
|
||||
return new AESharedItemStack(newDef);
|
||||
}
|
||||
|
||||
private AESharedItemStack makeUpperBound(final ItemStack itemStack, final CompoundTag 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);
|
||||
}
|
||||
}
|
||||
|
||||
return new AESharedItemStack(newDef);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
public abstract class AEStack<T extends IAEStack<T>> implements IAEStack<T> {
|
||||
|
||||
private boolean isCraftable;
|
||||
private long stackSize;
|
||||
private long countRequestable;
|
||||
|
||||
@Override
|
||||
public long getStackSize() {
|
||||
return this.stackSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T setStackSize(final long ss) {
|
||||
this.stackSize = ss;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getCountRequestable() {
|
||||
return this.countRequestable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T setCountRequestable(final long countRequestable) {
|
||||
this.countRequestable = countRequestable;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCraftable() {
|
||||
return this.isCraftable;
|
||||
}
|
||||
|
||||
@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 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 void incStackSize(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 decCountRequestable(final long i) {
|
||||
this.countRequestable -= i;
|
||||
}
|
||||
|
||||
protected abstract boolean hasTagCompound();
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2020, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
abstract class AbstractItemList implements IItemList<IAEItemStack> {
|
||||
|
||||
@Override
|
||||
public void add(final IAEItemStack option) {
|
||||
if (option == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack st = this.getRecords().get(((AEItemStack) option).getSharedStack());
|
||||
|
||||
if (st != null) {
|
||||
st.add(option);
|
||||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack opt = option.copy();
|
||||
|
||||
this.putItemRecord(opt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack findPrecise(final IAEItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.getRecords().get(((AEItemStack) itemStack).getSharedStack());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IAEItemStack> findFuzzy(final IAEItemStack filter, final FuzzyMode fuzzy) {
|
||||
if (filter == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return this.getRecords().values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStorage(final IAEItemStack option) {
|
||||
if (option == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack st = this.getRecords().get(((AEItemStack) option).getSharedStack());
|
||||
|
||||
if (st != null) {
|
||||
st.incStackSize(option.getStackSize());
|
||||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack opt = option.copy();
|
||||
|
||||
this.putItemRecord(opt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCrafting(final IAEItemStack option) {
|
||||
if (option == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack st = this.getRecords().get(((AEItemStack) option).getSharedStack());
|
||||
|
||||
if (st != null) {
|
||||
st.setCraftable(true);
|
||||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack opt = option.copy();
|
||||
opt.setStackSize(0);
|
||||
opt.setCraftable(true);
|
||||
|
||||
this.putItemRecord(opt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequestable(final IAEItemStack option) {
|
||||
if (option == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final IAEItemStack st = this.getRecords().get(((AEItemStack) option).getSharedStack());
|
||||
|
||||
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());
|
||||
|
||||
this.putItemRecord(opt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack getFirstItem() {
|
||||
for (final IAEItemStack stackType : this) {
|
||||
return stackType;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
int size = 0;
|
||||
for (IAEItemStack entry : getRecords().values()) {
|
||||
if (entry.isMeaningful()) {
|
||||
size++;
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IAEItemStack> iterator() {
|
||||
return new MeaningfulItemIterator<>(this.getRecords().values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetStatus() {
|
||||
for (final IAEItemStack i : this) {
|
||||
i.reset();
|
||||
}
|
||||
}
|
||||
|
||||
abstract Map<AESharedItemStack, IAEItemStack> getRecords();
|
||||
|
||||
private IAEItemStack putItemRecord(final IAEItemStack itemStack) {
|
||||
return this.getRecords().put(((AEItemStack) itemStack).getSharedStack(), itemStack);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2020, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
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<>();
|
||||
|
||||
@Override
|
||||
public Collection<IAEItemStack> findFuzzy(final IAEItemStack filter, final FuzzyMode fuzzy) {
|
||||
if (filter == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return this.findFuzzyDamage(filter, fuzzy);
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
return this.records.subMap(bounds.lower(), true, bounds.upper(), true).descendingMap().values();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,185 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2020, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
public final class ItemList implements IItemList<IAEItemStack> {
|
||||
|
||||
private final static IItemList<IAEItemStack> NULL_ITEMLIST = new NullItemList();
|
||||
|
||||
private final Map<Item, IItemList<IAEItemStack>> records = new IdentityHashMap<>();
|
||||
|
||||
@Override
|
||||
public IAEItemStack findPrecise(final IAEItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.getRecord(itemStack.getItem()).findPrecise(itemStack);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return !this.iterator().hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(final IAEItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.getOrCreateRecord(itemStack.getItem()).add(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStorage(final IAEItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.getOrCreateRecord(itemStack.getItem()).addStorage(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCrafting(final IAEItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.getOrCreateRecord(itemStack.getItem()).addCrafting(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequestable(final IAEItemStack itemStack) {
|
||||
if (itemStack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.getOrCreateRecord(itemStack.getItem()).addRequestable(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack getFirstItem() {
|
||||
for (final IAEItemStack stackType : this) {
|
||||
return stackType;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
int size = 0;
|
||||
for (IItemList<IAEItemStack> entry : records.values()) {
|
||||
size += entry.size();
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IAEItemStack> iterator() {
|
||||
return new ChainedIterator(this.records.values().iterator());
|
||||
}
|
||||
|
||||
@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> 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 class ChainedIterator implements Iterator<IAEItemStack> {
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack next() {
|
||||
if (this.next == null) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
return this.next.next();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.channels.IItemStorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemContainer;
|
||||
|
||||
public class ItemModList implements IItemContainer<IAEItemStack> {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@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 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();
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2020, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
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<>();
|
||||
|
||||
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();
|
||||
|
||||
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));
|
||||
|
||||
this.next = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
if (this.next == null) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
return this.next;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
this.parent.remove();
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2020, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
public class NullItemList implements IItemList<IAEItemStack> {
|
||||
|
||||
@Override
|
||||
public void add(IAEItemStack option) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack findPrecise(IAEItemStack i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IAEItemStack> findFuzzy(IAEItemStack input, FuzzyMode fuzzy) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStorage(IAEItemStack option) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCrafting(IAEItemStack option) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequestable(IAEItemStack option) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack getFirstItem() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<IAEItemStack> iterator() {
|
||||
return Collections.emptyIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetStatus() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2020, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.item;
|
||||
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
|
||||
class StrictItemList extends AbstractItemList {
|
||||
|
||||
private final Map<AESharedItemStack, IAEItemStack> records = new IdentityHashMap<>();
|
||||
|
||||
@Override
|
||||
Map<AESharedItemStack, IAEItemStack> getRecords() {
|
||||
return this.records;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
private int counter = 0;
|
||||
|
||||
public AEInvIterator(final AppEngInternalAEInventory inventory) {
|
||||
this.inventory = inventory;
|
||||
this.size = this.inventory.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.counter < this.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack next() {
|
||||
final IAEItemStack result = this.inventory.getAEStackInSlot(this.counter);
|
||||
|
||||
this.counter++;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.iterators;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public final class ChainedIterator<T> implements Iterator<T> {
|
||||
private final T[] list;
|
||||
|
||||
private int offset = 0;
|
||||
|
||||
public ChainedIterator(final T... list) {
|
||||
this.list = list;
|
||||
}
|
||||
|
||||
@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 void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.iterators;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import alexiil.mc.lib.attributes.item.FixedItemInv;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public final class InvIterator implements Iterator<ItemStack> {
|
||||
private final FixedItemInv inventory;
|
||||
private final int size;
|
||||
|
||||
private int counter = 0;
|
||||
|
||||
public InvIterator(final FixedItemInv inventory) {
|
||||
this.inventory = inventory;
|
||||
this.size = this.inventory.getSlotCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.counter < this.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack next() {
|
||||
final ItemStack result = this.inventory.getInvStack(this.counter);
|
||||
this.counter++;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.iterators;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class NullIterator<T> implements Iterator<T> {
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T next() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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 ProxyNodeIterator(final Iterator<IGridHost> hosts) {
|
||||
this.hosts = hosts;
|
||||
}
|
||||
|
||||
@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 void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.iterators;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.util.inv.ItemSlot;
|
||||
|
||||
public class StackToSlotIterator implements Iterator<ItemSlot> {
|
||||
|
||||
private final ItemSlot iss = new ItemSlot();
|
||||
private final Iterator<ItemStack> is;
|
||||
private int x = 0;
|
||||
|
||||
public StackToSlotIterator(final Iterator<ItemStack> is) {
|
||||
this.is = is;
|
||||
}
|
||||
|
||||
@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 void remove() {
|
||||
// uhh no.
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.prioritylist;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
public class DefaultPriorityList<T extends IAEStack<T>> implements IPartitionList<T> {
|
||||
|
||||
@Override
|
||||
public boolean isListed(final T input) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> getItems() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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> {
|
||||
|
||||
private final IItemList<T> list;
|
||||
private final FuzzyMode 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 isEmpty() {
|
||||
return this.list.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> getItems() {
|
||||
return this.list;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.prioritylist;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
|
||||
public interface IPartitionList<T extends IAEStack<T>> {
|
||||
boolean isListed(T input);
|
||||
|
||||
boolean isEmpty();
|
||||
|
||||
Iterable<T> getItems();
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.positive.isEmpty() && this.negative.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> getItems() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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> {
|
||||
|
||||
private final IItemList<T> list;
|
||||
|
||||
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 isEmpty() {
|
||||
return this.list.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<T> getItems() {
|
||||
return this.list;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user