make it work
This commit is contained in:
@@ -25,7 +25,6 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import appeng.helpers.NonBlockingItems;
|
|
||||||
import com.google.common.base.Stopwatch;
|
import com.google.common.base.Stopwatch;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
|||||||
@@ -8,21 +8,20 @@ import appeng.core.AEConfig;
|
|||||||
import appeng.core.AELog;
|
import appeng.core.AELog;
|
||||||
import appeng.util.item.AEItemStack;
|
import appeng.util.item.AEItemStack;
|
||||||
import gregtech.api.items.metaitem.MetaItem;
|
import gregtech.api.items.metaitem.MetaItem;
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.fml.common.Loader;
|
import net.minecraftforge.fml.common.Loader;
|
||||||
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
public class NonBlockingItems
|
public class NonBlockingItems
|
||||||
{
|
{
|
||||||
public static final NonBlockingItems INSTANCE = new NonBlockingItems();
|
public static Map<String, IItemList<IAEItemStack>> NON_BLOCKING_MAP = new HashMap<>();
|
||||||
public static Map<String, IItemList<IAEItemStack>> NON_BLOCKING_MAP;
|
public static NonBlockingItems INSTANCE = new NonBlockingItems();
|
||||||
|
|
||||||
NonBlockingItems()
|
private NonBlockingItems()
|
||||||
{
|
{
|
||||||
NON_BLOCKING_MAP = new HashMap<>();
|
|
||||||
String[] strings = AEConfig.instance().getNonBlockingItems();
|
String[] strings = AEConfig.instance().getNonBlockingItems();
|
||||||
String modid = "";
|
String modid = "";
|
||||||
if( strings.length > 0 )
|
if( strings.length > 0 )
|
||||||
@@ -62,11 +61,9 @@ public class NonBlockingItems
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Item item = Item.getByNameOrId( ModItemMeta[0] + ":" + ModItemMeta[1] );
|
ItemStack itemStack = GameRegistry.makeItemStack( ModItemMeta[0] + ":" + ModItemMeta[1], ModItemMeta.length == 3 ? Integer.parseInt( ModItemMeta[2] ) : 0, 1, null );
|
||||||
if( item != null )
|
if( !itemStack.isEmpty() )
|
||||||
{
|
{
|
||||||
ItemStack itemStack;
|
|
||||||
itemStack = new ItemStack( item, 1, ModItemMeta.length == 3 ? Integer.parseInt( ModItemMeta[2] ) : 0 );
|
|
||||||
NON_BLOCKING_MAP.get( modid ).add( AEItemStack.fromItemStack( itemStack ) );
|
NON_BLOCKING_MAP.get( modid ).add( AEItemStack.fromItemStack( itemStack ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -30,16 +30,8 @@ public class BlockingItemHandler extends BlockingInventoryAdaptor
|
|||||||
boolean isBlockableItem( ItemStack stack )
|
boolean isBlockableItem( ItemStack stack )
|
||||||
{
|
{
|
||||||
IItemList<IAEItemStack> itemList = NonBlockingItems.INSTANCE.getMap().get( domain );
|
IItemList<IAEItemStack> itemList = NonBlockingItems.INSTANCE.getMap().get( domain );
|
||||||
if( stack.getItem().isDamageable() )
|
Collection<IAEItemStack> item = itemList.findFuzzy( AEItemStack.fromItemStack( stack ), FuzzyMode.IGNORE_ALL );
|
||||||
{
|
return item.isEmpty();
|
||||||
Collection<IAEItemStack> item = itemList.findFuzzy( AEItemStack.fromItemStack( stack ), FuzzyMode.IGNORE_ALL );
|
|
||||||
return item.isEmpty();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
IAEItemStack item = itemList.findPrecise( AEItemStack.fromItemStack( stack ) );
|
|
||||||
return item == null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -22,72 +22,78 @@ import java.util.Objects;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
final class AESharedItemStack {
|
|
||||||
|
|
||||||
private final ItemStack itemStack;
|
final class AESharedItemStack
|
||||||
private final int itemId;
|
{
|
||||||
private final int itemDamage;
|
|
||||||
private final int hashCode;
|
|
||||||
|
|
||||||
public AESharedItemStack(final ItemStack itemStack) {
|
private final ItemStack itemStack;
|
||||||
this(itemStack, itemStack.getItemDamage());
|
private final int itemDamage;
|
||||||
}
|
private final int hashCode;
|
||||||
|
|
||||||
/**
|
public AESharedItemStack( final ItemStack itemStack )
|
||||||
* A constructor to explicitly set the damage value and not fetch it from the {@link ItemStack}
|
{
|
||||||
*
|
this( itemStack, itemStack.getItemDamage() );
|
||||||
* @param itemStack The {@link ItemStack} to filter
|
}
|
||||||
* @param damage The damage of the item
|
|
||||||
*/
|
|
||||||
private AESharedItemStack(ItemStack itemStack, int damage) {
|
|
||||||
this.itemStack = itemStack;
|
|
||||||
this.itemId = Item.getIdFromItem(itemStack.getItem());
|
|
||||||
this.itemDamage = damage;
|
|
||||||
|
|
||||||
// Ensure this is always called last.
|
/**
|
||||||
this.hashCode = this.makeHashCode();
|
* A constructor to explicitly set the damage value and not fetch it from the {@link ItemStack}
|
||||||
}
|
*
|
||||||
|
* @param itemStack The {@link ItemStack} to filter
|
||||||
|
* @param damage The damage of the item
|
||||||
|
*/
|
||||||
|
private AESharedItemStack( ItemStack itemStack, int damage )
|
||||||
|
{
|
||||||
|
this.itemStack = itemStack;
|
||||||
|
this.itemDamage = damage;
|
||||||
|
|
||||||
ItemStack getDefinition() {
|
// Ensure this is always called last.
|
||||||
return this.itemStack;
|
this.hashCode = this.makeHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
int getItemDamage() {
|
ItemStack getDefinition()
|
||||||
return this.itemDamage;
|
{
|
||||||
}
|
return this.itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
int getItemDamage()
|
||||||
public int hashCode() {
|
{
|
||||||
return this.hashCode;
|
return this.itemDamage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(final Object obj) {
|
public int hashCode()
|
||||||
if (this == obj) {
|
{
|
||||||
return true;
|
return this.hashCode;
|
||||||
}
|
}
|
||||||
if (!(obj instanceof AESharedItemStack)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final AESharedItemStack other = (AESharedItemStack) obj;
|
@Override
|
||||||
Preconditions.checkState(this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1");
|
public boolean equals( final Object obj )
|
||||||
Preconditions.checkArgument(other.getDefinition().getCount() == 1, "ItemStack#getCount() has to be 1");
|
{
|
||||||
|
if( this == obj )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if( !( obj instanceof AESharedItemStack ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.itemStack == other.itemStack) {
|
final AESharedItemStack other = (AESharedItemStack) obj;
|
||||||
return true;
|
Preconditions.checkState( this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1" );
|
||||||
}
|
Preconditions.checkArgument( other.getDefinition().getCount() == 1, "ItemStack#getCount() has to be 1" );
|
||||||
return ItemStack.areItemStacksEqual(this.itemStack, other.itemStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int makeHashCode() {
|
if( this.itemStack == other.itemStack )
|
||||||
return Objects.hash(
|
{
|
||||||
this.itemId,
|
return true;
|
||||||
this.itemDamage,
|
}
|
||||||
this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound() : 0);
|
return ItemStack.areItemStacksEqual( this.itemStack, other.itemStack );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int makeHashCode()
|
||||||
|
{
|
||||||
|
return Objects.hash( this.itemStack.getItem(), this.itemDamage, this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound() : 0 );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user