pick 97420a31d The big reformat of 2020

This commit is contained in:
yueh
2020-06-16 21:41:28 +02:00
parent 5304b3febe
commit 5225ea426b
2252 changed files with 95466 additions and 118582 deletions
@@ -18,7 +18,6 @@
package appeng.util.helpers;
import javax.annotation.Nonnull;
import net.minecraft.item.Item;
@@ -27,81 +26,70 @@ import net.minecraft.nbt.CompoundNBT;
import appeng.api.config.FuzzyMode;
/**
* A helper class for comparing {@link Item}, {@link ItemStack} or NBT
*
*/
public class ItemComparisonHelper
{
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();
}
/**
* 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() );
}
/**
* 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;
}
/**
* 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;
}
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();
// 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 );
}
}
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 );
@@ -111,39 +99,36 @@ public class ItemComparisonHelper
// return true;
// }
return a.isItemEqual( b );
}
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 CompoundNBT left, final CompoundNBT right )
{
if( left == right )
{
return true;
}
/**
* 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 CompoundNBT left, final CompoundNBT right) {
if (left == right) {
return true;
}
final boolean isLeftEmpty = left == null || left.isEmpty();
final boolean isRightEmpty = right == null || right.isEmpty();
final boolean isLeftEmpty = left == null || left.isEmpty();
final boolean isRightEmpty = right == null || right.isEmpty();
if( isLeftEmpty && isRightEmpty )
{
return true;
}
if (isLeftEmpty && isRightEmpty) {
return true;
}
if( isLeftEmpty != isRightEmpty )
{
return false;
}
if (isLeftEmpty != isRightEmpty) {
return false;
}
if( left != null )
{
return left.equals( right );
}
if (left != null) {
return left.equals(right);
}
return false;
}
return false;
}
}