1.15 port

This commit is contained in:
yueh
2020-05-18 14:02:45 +02:00
parent 0ea86c939c
commit 16d6d55d7f
630 changed files with 4211 additions and 12664 deletions
+27 -59
View File
@@ -21,7 +21,6 @@ package appeng.util.item;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -30,11 +29,11 @@ import io.netty.buffer.ByteBuf;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.items.ItemHandlerHelper;
import appeng.api.AEApi;
@@ -48,13 +47,12 @@ import appeng.util.Platform;
public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack
{
private AESharedItemStack sharedStack;
private Optional<OreReference> oreReference;
@SideOnly( Side.CLIENT )
@OnlyIn( Dist.CLIENT )
private String displayName;
@SideOnly( Side.CLIENT )
@OnlyIn( Dist.CLIENT )
private List<String> tooltip;
@SideOnly( Side.CLIENT )
@OnlyIn( Dist.CLIENT )
private ResourceLocation uniqueID;
private AEItemStack( final AEItemStack is )
@@ -63,7 +61,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
this.setCraftable( is.isCraftable() );
this.setCountRequestable( is.getCountRequestable() );
this.sharedStack = is.sharedStack;
this.oreReference = is.oreReference;
}
private AEItemStack( final AESharedItemStack is, long size )
@@ -72,7 +69,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
this.setStackSize( size );
this.setCraftable( false );
this.setCountRequestable( 0 );
this.oreReference = OreHelper.INSTANCE.getOre( is.getDefinition() );
}
@Nullable
@@ -86,14 +82,14 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
return new AEItemStack( AEItemStackRegistry.getRegisteredStack( stack ), stack.getCount() );
}
public static IAEItemStack fromNBT( final NBTTagCompound i )
public static IAEItemStack fromNBT( final CompoundNBT i )
{
if( i == null )
{
return null;
}
final ItemStack itemstack = new ItemStack( i );
final ItemStack itemstack = ItemStack.read( i );
if( itemstack.isEmpty() )
{
return null;
@@ -107,12 +103,12 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
}
@Override
public void writeToNBT( final NBTTagCompound i )
public void writeToNBT( final CompoundNBT i )
{
this.getDefinition().writeToNBT( i );
i.setLong( "Cnt", this.getStackSize() );
i.setLong( "Req", this.getCountRequestable() );
i.setBoolean( "Craft", this.isCraftable() );
this.getDefinition().write( i );
i.putLong( "Cnt", this.getStackSize() );
i.putLong( "Req", this.getCountRequestable() );
i.putBoolean( "Craft", this.isCraftable() );
}
public static AEItemStack fromPacket( final ByteBuf data )
@@ -122,7 +118,8 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
final byte countReqType = (byte) ( ( mask & 0x30 ) >> 4 );
final boolean isCraftable = ( mask & 0x40 ) > 0;
final ItemStack itemstack = new ItemStack( ByteBufUtils.readTag( data ) );
final PacketBuffer p = new PacketBuffer( data );
final ItemStack itemstack = p.readItemStack();
final long stackSize = getPacketValue( stackType, data );
final long countRequestable = getPacketValue( countReqType, data );
@@ -138,13 +135,13 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
}
@Override
public void writeToPacket( final ByteBuf i )
public void writeToPacket( final PacketBuffer i )
{
final byte mask = (byte) ( ( this.getType( this.getStackSize() ) << 2 ) | ( this
.getType( this.getCountRequestable() ) << 4 ) | ( (byte) ( this.isCraftable() ? 1 : 0 ) << 6 ) | ( this.hasTagCompound() ? 1 : 0 ) << 7 );
i.writeByte( mask );
ByteBufUtils.writeTag( i, this.getDefinition().serializeNBT() );
i.writeCompoundTag( this.getDefinition().serializeNBT() );
this.putPacketValue( i, this.getStackSize() );
this.putPacketValue( i, this.getCountRequestable() );
}
@@ -165,11 +162,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
@Override
public boolean fuzzyComparison( final IAEItemStack other, final FuzzyMode mode )
{
if( mode == FuzzyMode.IGNORE_ALL && OreHelper.INSTANCE.sameOre( this, other ) )
{
return true;
}
final ItemStack itemStack = this.getDefinition();
final ItemStack otherStack = other.getDefinition();
@@ -218,12 +210,6 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
return this.sharedStack.getItemDamage();
}
@Override
public boolean sameOre( final IAEItemStack is )
{
return OreHelper.INSTANCE.sameOre( this, is );
}
@Override
public boolean isSameType( final IAEItemStack otherStack )
{
@@ -274,10 +260,10 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
@Override
public String toString()
{
return this.getStackSize() + "x" + this.getDefinition().getItem().getUnlocalizedName() + "@" + this.getDefinition().getItemDamage();
return this.getStackSize() + "x" + this.getDefinition().getItem().getRegistryName();
}
@SideOnly( Side.CLIENT )
@OnlyIn( Dist.CLIENT )
public List<String> getToolTip()
{
if( this.tooltip == null )
@@ -287,7 +273,7 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
return this.tooltip;
}
@SideOnly( Side.CLIENT )
@OnlyIn( Dist.CLIENT )
public String getDisplayName()
{
if( this.displayName == null )
@@ -297,31 +283,16 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
return this.displayName;
}
@SideOnly( Side.CLIENT )
@OnlyIn( Dist.CLIENT )
public String getModID()
{
if( this.uniqueID == null )
{
this.uniqueID = Item.REGISTRY.getNameForObject( this.getDefinition().getItem() );
}
if( this.uniqueID == null )
{
return "** Null";
}
return this.uniqueID.getResourceDomain() == null ? "** Null" : this.uniqueID.getResourceDomain();
}
public Optional<OreReference> getOre()
{
return this.oreReference;
return this.getDefinition().getItem().getRegistryName().getNamespace();
}
@Override
public boolean hasTagCompound()
{
return this.getDefinition().hasTagCompound();
return this.getDefinition().hasTag();
}
@Override
@@ -353,21 +324,18 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
}
else if( mode == FuzzyMode.PERCENT_99 )
{
return ( a.getItemDamage() > 1 ) == ( b.getItemDamage() > 1 );
return ( a.getDamage() > 1 ) == ( b.getDamage() > 1 );
}
else
{
final float percentDamageOfA = (float) a.getItemDamage() / (float) a.getMaxDamage();
final float percentDamageOfB = (float) b.getItemDamage() / (float) b.getMaxDamage();
final float percentDamageOfA = (float) a.getDamage() / a.getMaxDamage();
final float percentDamageOfB = (float) b.getDamage() / b.getMaxDamage();
return ( percentDamageOfA > mode.breakPoint ) == ( percentDamageOfB > mode.breakPoint );
}
}
return a.getMetadata() == b.getMetadata();
}
return false;
}
}
@@ -25,15 +25,15 @@ import com.google.common.base.Preconditions;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.CompoundNBT;
import appeng.api.config.FuzzyMode;
final class AESharedItemStack implements Comparable<AESharedItemStack>
{
private static final NBTTagCompound LOW_TAG = new NBTTagCompound();
private static final NBTTagCompound HIGH_TAG = new NBTTagCompound();
private static final CompoundNBT LOW_TAG = new CompoundNBT();
private static final CompoundNBT HIGH_TAG = new CompoundNBT();
private final ItemStack itemStack;
private final int itemId;
@@ -44,7 +44,7 @@ final class AESharedItemStack implements Comparable<AESharedItemStack>
{
this.itemStack = itemStack;
this.itemId = Item.getIdFromItem( itemStack.getItem() );
this.itemDamage = itemStack.getItemDamage();
this.itemDamage = itemStack.getDamage();
this.hashCode = this.makeHashCode();
}
@@ -131,24 +131,24 @@ final class AESharedItemStack implements Comparable<AESharedItemStack>
private int compareNBT( final ItemStack b )
{
if( this.itemStack.getTagCompound() == b.getTagCompound() )
if( this.itemStack.getTag() == b.getTag() )
{
return 0;
}
if( this.itemStack.getTagCompound() == LOW_TAG || b.getTagCompound() == HIGH_TAG )
if( this.itemStack.getTag() == LOW_TAG || b.getTag() == HIGH_TAG )
{
return -1;
}
if( this.itemStack.getTagCompound() == HIGH_TAG || b.getTagCompound() == LOW_TAG )
if( this.itemStack.getTag() == HIGH_TAG || b.getTag() == LOW_TAG )
{
return 1;
}
return System.identityHashCode( this.itemStack.getTagCompound() ) - System.identityHashCode( b.getTagCompound() );
return System.identityHashCode( this.itemStack.getTag() ) - System.identityHashCode( b.getTag() );
}
private int makeHashCode()
{
return Objects.hash( this.itemId, this.itemDamage, this.itemStack.hasTagCompound() ? this.itemStack.getTagCompound() : 0 );
return Objects.hash( this.itemId, this.itemDamage, this.itemStack.hasTag() ? this.itemStack.getTag() : 0 );
}
/**
@@ -170,7 +170,7 @@ final class AESharedItemStack implements Comparable<AESharedItemStack>
Preconditions.checkState( !stack.isEmpty(), "ItemStack#isEmpty() has to be false" );
Preconditions.checkState( stack.getCount() == 1, "ItemStack#getCount() has to be 1" );
final NBTTagCompound tag = stack.hasTagCompound() ? stack.getTagCompound() : null;
final CompoundNBT tag = stack.hasTag() ? stack.getTag() : null;
this.lower = this.makeLowerBound( stack, tag, fuzzy, ignoreMeta );
this.upper = this.makeUpperBound( stack, tag, fuzzy, ignoreMeta );
@@ -186,14 +186,14 @@ final class AESharedItemStack implements Comparable<AESharedItemStack>
return this.upper;
}
private AESharedItemStack makeLowerBound( final ItemStack itemStack, final NBTTagCompound tag, final FuzzyMode fuzzy, final boolean ignoreMeta )
private AESharedItemStack makeLowerBound( final ItemStack itemStack, final CompoundNBT tag, final FuzzyMode fuzzy, final boolean ignoreMeta )
{
final ItemStack newDef = itemStack.copy();
if( ignoreMeta )
{
newDef.setItemDamage( MIN_DAMAGE_VALUE );
newDef.setTagCompound( tag );
newDef.setDamage( MIN_DAMAGE_VALUE );
newDef.setTag( tag );
}
else
{
@@ -201,40 +201,40 @@ final class AESharedItemStack implements Comparable<AESharedItemStack>
{
if( fuzzy == FuzzyMode.IGNORE_ALL )
{
newDef.setItemDamage( MIN_DAMAGE_VALUE );
newDef.setDamage( MIN_DAMAGE_VALUE );
}
else if( fuzzy == FuzzyMode.PERCENT_99 )
{
if( itemStack.getItemDamage() == MIN_DAMAGE_VALUE )
if( itemStack.getDamage() == MIN_DAMAGE_VALUE )
{
newDef.setItemDamage( MIN_DAMAGE_VALUE );
newDef.setDamage( MIN_DAMAGE_VALUE );
}
else
{
newDef.setItemDamage( MIN_DAMAGE_VALUE + 1 );
newDef.setDamage( MIN_DAMAGE_VALUE + 1 );
}
}
else
{
final int breakpoint = fuzzy.calculateBreakPoint( itemStack.getMaxDamage() );
final int damage = breakpoint <= itemStack.getItemDamage() ? breakpoint : 0;
newDef.setItemDamage( damage );
final int damage = breakpoint <= itemStack.getDamage() ? breakpoint : 0;
newDef.setDamage( damage );
}
}
newDef.setTagCompound( LOW_TAG );
newDef.setTag( LOW_TAG );
}
return new AESharedItemStack( newDef );
}
private AESharedItemStack makeUpperBound( final ItemStack itemStack, final NBTTagCompound tag, final FuzzyMode fuzzy, final boolean ignoreMeta )
private AESharedItemStack makeUpperBound( final ItemStack itemStack, final CompoundNBT tag, final FuzzyMode fuzzy, final boolean ignoreMeta )
{
final ItemStack newDef = itemStack.copy();
if( ignoreMeta )
{
newDef.setItemDamage( MAX_DAMAGE_VALUE );
newDef.setTagCompound( tag );
newDef.setDamage( MAX_DAMAGE_VALUE );
newDef.setTag( tag );
}
else
{
@@ -242,27 +242,27 @@ final class AESharedItemStack implements Comparable<AESharedItemStack>
{
if( fuzzy == FuzzyMode.IGNORE_ALL )
{
newDef.setItemDamage( itemStack.getMaxDamage() + 1 );
newDef.setDamage( itemStack.getMaxDamage() + 1 );
}
else if( fuzzy == FuzzyMode.PERCENT_99 )
{
if( itemStack.getItemDamage() == MIN_DAMAGE_VALUE )
if( itemStack.getDamage() == MIN_DAMAGE_VALUE )
{
newDef.setItemDamage( MIN_DAMAGE_VALUE );
newDef.setDamage( MIN_DAMAGE_VALUE );
}
else
{
newDef.setItemDamage( itemStack.getMaxDamage() + 1 );
newDef.setDamage( itemStack.getMaxDamage() + 1 );
}
}
else
{
final int breakpoint = fuzzy.calculateBreakPoint( itemStack.getMaxDamage() );
final int damage = itemStack.getItemDamage() < breakpoint ? breakpoint - 1 : itemStack.getMaxDamage() + 1;
newDef.setItemDamage( damage );
final int damage = itemStack.getDamage() < breakpoint ? breakpoint - 1 : itemStack.getMaxDamage() + 1;
newDef.setDamage( damage );
}
}
newDef.setTagCompound( HIGH_TAG );
newDef.setTag( HIGH_TAG );
}
return new AESharedItemStack( newDef );
+1 -23
View File
@@ -19,15 +19,12 @@
package appeng.util.item;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.NavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
@@ -81,26 +78,7 @@ public final class ItemList implements IItemList<IAEItemStack>
final AEItemStack ais = (AEItemStack) filter;
return ais.getOre().map( or ->
{
if( or.getAEEquivalents().size() == 1 )
{
final IAEItemStack is = or.getAEEquivalents().get( 0 );
return this.findFuzzyDamage( is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE );
}
else
{
final Collection<IAEItemStack> output = new ArrayList<>();
for( final IAEItemStack is : or.getAEEquivalents() )
{
output.addAll( this.findFuzzyDamage( is, fuzzy, is.getItemDamage() == OreDictionary.WILDCARD_VALUE ) );
}
return output;
}
} ).orElse( this.findFuzzyDamage( ais, fuzzy, false ) );
return this.findFuzzyDamage( ais, fuzzy, false );
}
@Override
@@ -1,222 +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 java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.storage.data.IAEItemStack;
public class OreHelper
{
public static final OreHelper INSTANCE = new OreHelper();
/**
* A local cache to speed up OreDictionary lookups.
*/
private final LoadingCache<String, List<ItemStack>> oreDictCache = CacheBuilder.newBuilder().build( new CacheLoader<String, List<ItemStack>>()
{
@Override
public List<ItemStack> load( final String oreName )
{
return OreDictionary.getOres( oreName );
}
} );
private final Map<ItemRef, OreReference> references = new HashMap<>();
/**
* Test if the passed {@link ItemStack} is an ore.
*
* @param itemStack the itemstack to test
*
* @return true if an ore entry exists, false otherwise
*/
public Optional<OreReference> getOre( final ItemStack itemStack )
{
final ItemRef ir = new ItemRef( itemStack );
if( !this.references.containsKey( ir ) )
{
final OreReference ref = new OreReference();
final Collection<Integer> ores = ref.getOres();
final Collection<String> set = ref.getEquivalents();
final Set<String> toAdd = new HashSet<>();
for( final String ore : OreDictionary.getOreNames() )
{
// skip ore if it is a match already or null.
if( ore == null || toAdd.contains( ore ) )
{
continue;
}
for( final ItemStack oreItem : this.oreDictCache.getUnchecked( ore ) )
{
if( OreDictionary.itemMatches( oreItem, itemStack, false ) )
{
toAdd.add( ore );
break;
}
}
}
for( final String ore : toAdd )
{
set.add( ore );
ores.add( OreDictionary.getOreID( ore ) );
}
if( !set.isEmpty() )
{
this.references.put( ir, ref );
}
else
{
this.references.put( ir, null );
}
}
return Optional.ofNullable( this.references.get( ir ) );
}
boolean sameOre( final AEItemStack aeItemStack, final IAEItemStack is )
{
final OreReference a = aeItemStack.getOre().orElse( null );
final OreReference b = aeItemStack.getOre().orElse( null );
return this.sameOre( a, b );
}
public boolean sameOre( final OreReference a, final OreReference b )
{
if( a == null || b == null )
{
return false;
}
if( a == b )
{
return true;
}
final Collection<Integer> bOres = b.getOres();
for( final Integer ore : a.getOres() )
{
if( bOres.contains( ore ) )
{
return true;
}
}
return false;
}
boolean sameOre( final AEItemStack aeItemStack, final ItemStack o )
{
return aeItemStack.getOre().map( a ->
{
for( final String oreName : a.getEquivalents() )
{
for( final ItemStack oreItem : this.oreDictCache.getUnchecked( oreName ) )
{
if( OreDictionary.itemMatches( oreItem, o, false ) )
{
return true;
}
}
}
return false;
} )
.orElse( false );
}
List<ItemStack> getCachedOres( final String oreName )
{
return this.oreDictCache.getUnchecked( oreName );
}
private static class ItemRef
{
private final Item ref;
private final int damage;
private final int hash;
ItemRef( final ItemStack stack )
{
this.ref = stack.getItem();
if( stack.getItem().isDamageable() )
{
this.damage = 0; // IGNORED
}
else
{
this.damage = stack.getItemDamage(); // might be important...
}
this.hash = this.ref.hashCode() ^ this.damage;
}
@Override
public int hashCode()
{
return this.hash;
}
@Override
public boolean equals( final Object obj )
{
if( obj == null )
{
return false;
}
if( this.getClass() != obj.getClass() )
{
return false;
}
final ItemRef other = (ItemRef) obj;
return this.damage == other.damage && this.ref == other.ref;
}
@Override
public String toString()
{
return "ItemRef [ref=" + this.ref.getUnlocalizedName() + ", damage=" + this.damage + ", hash=" + this.hash + ']';
}
}
}
@@ -1,72 +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.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import appeng.api.storage.data.IAEItemStack;
public class OreReference
{
private final List<String> otherOptions = new ArrayList<>();
private final Set<Integer> ores = new HashSet<>();
private List<IAEItemStack> aeOtherOptions = null;
Collection<String> getEquivalents()
{
return this.otherOptions;
}
List<IAEItemStack> getAEEquivalents()
{
if( this.aeOtherOptions == null )
{
this.aeOtherOptions = new ArrayList<>( this.otherOptions.size() );
// SUMMON AE STACKS!
for( final String oreName : this.otherOptions )
{
for( final ItemStack is : OreHelper.INSTANCE.getCachedOres( oreName ) )
{
if( is.getItem() != Items.AIR )
{
this.aeOtherOptions.add( AEItemStack.fromItemStack( is ) );
}
}
}
}
return this.aeOtherOptions;
}
Collection<Integer> getOres()
{
return this.ores;
}
}