make it work

This commit is contained in:
PrototypeTrousers
2022-02-10 17:59:03 -03:00
parent 6d25b7ef3c
commit 64f29a7dba
4 changed files with 68 additions and 74 deletions
-1
View File
@@ -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,17 +30,9 @@ 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 ); Collection<IAEItemStack> item = itemList.findFuzzy( AEItemStack.fromItemStack( stack ), FuzzyMode.IGNORE_ALL );
return item.isEmpty(); return item.isEmpty();
} }
else
{
IAEItemStack item = itemList.findPrecise( AEItemStack.fromItemStack( stack ) );
return item == null;
}
}
@Override @Override
public boolean containsBlockingItems() public boolean containsBlockingItems()
@@ -22,18 +22,19 @@ 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 {
final class AESharedItemStack
{
private final ItemStack itemStack; private final ItemStack itemStack;
private final int itemId;
private final int itemDamage; private final int itemDamage;
private final int hashCode; private final int hashCode;
public AESharedItemStack(final ItemStack itemStack) { public AESharedItemStack( final ItemStack itemStack )
this(itemStack, itemStack.getItemDamage()); {
this( itemStack, itemStack.getItemDamage() );
} }
/** /**
@@ -42,52 +43,57 @@ final class AESharedItemStack {
* @param itemStack The {@link ItemStack} to filter * @param itemStack The {@link ItemStack} to filter
* @param damage The damage of the item * @param damage The damage of the item
*/ */
private AESharedItemStack(ItemStack itemStack, int damage) { private AESharedItemStack( ItemStack itemStack, int damage )
{
this.itemStack = itemStack; this.itemStack = itemStack;
this.itemId = Item.getIdFromItem(itemStack.getItem());
this.itemDamage = damage; this.itemDamage = damage;
// Ensure this is always called last. // Ensure this is always called last.
this.hashCode = this.makeHashCode(); this.hashCode = this.makeHashCode();
} }
ItemStack getDefinition() { ItemStack getDefinition()
{
return this.itemStack; return this.itemStack;
} }
int getItemDamage() { int getItemDamage()
{
return this.itemDamage; return this.itemDamage;
} }
@Override @Override
public int hashCode() { public int hashCode()
{
return this.hashCode; return this.hashCode;
} }
@Override @Override
public boolean equals(final Object obj) { public boolean equals( final Object obj )
if (this == obj) { {
if( this == obj )
{
return true; return true;
} }
if (!(obj instanceof AESharedItemStack)) { if( !( obj instanceof AESharedItemStack ) )
{
return false; return false;
} }
final AESharedItemStack other = (AESharedItemStack) obj; final AESharedItemStack other = (AESharedItemStack) obj;
Preconditions.checkState(this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1"); Preconditions.checkState( this.itemStack.getCount() == 1, "ItemStack#getCount() has to be 1" );
Preconditions.checkArgument(other.getDefinition().getCount() == 1, "ItemStack#getCount() has to be 1"); Preconditions.checkArgument( other.getDefinition().getCount() == 1, "ItemStack#getCount() has to be 1" );
if (this.itemStack == other.itemStack) { if( this.itemStack == other.itemStack )
{
return true; return true;
} }
return ItemStack.areItemStacksEqual(this.itemStack, other.itemStack); return ItemStack.areItemStacksEqual( this.itemStack, other.itemStack );
} }
private int makeHashCode() { private int makeHashCode()
return Objects.hash( {
this.itemId, return Objects.hash( this.itemStack.getItem(), this.itemDamage, this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound() : 0 );
this.itemDamage,
this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound() : 0);
} }
} }