Skip to content

Commit

Permalink
make it work
Browse files Browse the repository at this point in the history
  • Loading branch information
PrototypeTrousers committed Feb 10, 2022
1 parent 6d25b7e commit 64f29a7
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 85 deletions.
1 change: 0 additions & 1 deletion src/main/java/appeng/core/AppEng.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import javax.annotation.Nonnull;

import appeng.helpers.NonBlockingItems;
import com.google.common.base.Stopwatch;
import com.google.common.collect.Lists;

Expand Down
15 changes: 6 additions & 9 deletions src/main/java/appeng/helpers/NonBlockingItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@
import appeng.core.AELog;
import appeng.util.item.AEItemStack;
import gregtech.api.items.metaitem.MetaItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.registry.GameRegistry;

import java.util.*;


public class NonBlockingItems
{
public static final NonBlockingItems INSTANCE = new NonBlockingItems();
public static Map<String, IItemList<IAEItemStack>> NON_BLOCKING_MAP;
public static Map<String, IItemList<IAEItemStack>> NON_BLOCKING_MAP = new HashMap<>();
public static NonBlockingItems INSTANCE = new NonBlockingItems();

NonBlockingItems()
private NonBlockingItems()
{
NON_BLOCKING_MAP = new HashMap<>();
String[] strings = AEConfig.instance().getNonBlockingItems();
String modid = "";
if( strings.length > 0 )
Expand Down Expand Up @@ -62,11 +61,9 @@ public class NonBlockingItems
}
else
{
Item item = Item.getByNameOrId( ModItemMeta[0] + ":" + ModItemMeta[1] );
if( item != null )
ItemStack itemStack = GameRegistry.makeItemStack( ModItemMeta[0] + ":" + ModItemMeta[1], ModItemMeta.length == 3 ? Integer.parseInt( ModItemMeta[2] ) : 0, 1, 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 ) );
}
else
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/appeng/util/inv/BlockingItemHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,8 @@ public BlockingItemHandler( IItemHandler itemHandler, String domain )
boolean isBlockableItem( ItemStack stack )
{
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();
}
else
{
IAEItemStack item = itemList.findPrecise( AEItemStack.fromItemStack( stack ) );
return item == null;
}
Collection<IAEItemStack> item = itemList.findFuzzy( AEItemStack.fromItemStack( stack ), FuzzyMode.IGNORE_ALL );
return item.isEmpty();
}

@Override
Expand Down
136 changes: 71 additions & 65 deletions src/main/java/appeng/util/item/AESharedItemStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,72 +22,78 @@

import com.google.common.base.Preconditions;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

final class 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.getItemDamage());
}

/**
* 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.itemId = Item.getIdFromItem(itemStack.getItem());
this.itemDamage = damage;

// Ensure this is always called last.
this.hashCode = this.makeHashCode();
}

ItemStack getDefinition() {
return this.itemStack;
}

int getItemDamage() {
return this.itemDamage;
}

@Override
public int hashCode() {
return this.hashCode;
}

@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof AESharedItemStack)) {
return false;
}

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.areItemStacksEqual(this.itemStack, other.itemStack);
}

private int makeHashCode() {
return Objects.hash(
this.itemId,
this.itemDamage,
this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound() : 0);
}

final class AESharedItemStack
{

private final ItemStack itemStack;
private final int itemDamage;
private final int hashCode;

public AESharedItemStack( final ItemStack itemStack )
{
this( itemStack, itemStack.getItemDamage() );
}

/**
* 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;

// Ensure this is always called last.
this.hashCode = this.makeHashCode();
}

ItemStack getDefinition()
{
return this.itemStack;
}

int getItemDamage()
{
return this.itemDamage;
}

@Override
public int hashCode()
{
return this.hashCode;
}

@Override
public boolean equals( final Object obj )
{
if( this == obj )
{
return true;
}
if( !( obj instanceof AESharedItemStack ) )
{
return false;
}

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.areItemStacksEqual( this.itemStack, other.itemStack );
}

private int makeHashCode()
{
return Objects.hash( this.itemStack.getItem(), this.itemDamage, this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound() : 0 );
}

}

0 comments on commit 64f29a7

Please sign in to comment.