Fix container item crafting (again)

avoid making some copies
fix crash without JEI
This commit is contained in:
PrototypeTrousers
2022-03-15 23:42:56 -03:00
parent ccc8486571
commit 706e577dab
12 changed files with 130 additions and 191 deletions
+46 -47
View File
@@ -36,6 +36,7 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import gregtech.api.items.IToolItem;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
@@ -73,6 +74,7 @@ import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.Optional;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreDictionary;
@@ -134,6 +136,7 @@ import appeng.util.prioritylist.IPartitionList;
* @version rv2
* @since rv0
*/
@Optional.Interface( iface = "gregtech.api.items.IToolItem", modid = "gregtech" )
public class Platform
{
@@ -176,9 +179,8 @@ public class Platform
/**
* This displays the value for encoded longs ( double *100 )
*
* @param n to be formatted long value
* @param n to be formatted long value
* @param isRate if true it adds a /t to the formatted string
*
* @return formatted long value
*/
public static String formatPowerLong( final long n, final boolean isRate )
@@ -188,12 +190,14 @@ public class Platform
final PowerUnits displayUnits = AEConfig.instance().selectedPowerUnit();
p = PowerUnits.AE.convertTo( displayUnits, p );
final String[] preFixes = { "k", "M", "G", "T", "P", "T", "P", "E", "Z", "Y" };
final String[] preFixes = {
"k", "M", "G", "T", "P", "T", "P", "E", "Z", "Y"
};
String unitName = displayUnits.name();
String level = "";
int offset = 0;
while( p > 1000 && offset < preFixes.length )
while ( p > 1000 && offset < preFixes.length )
{
p /= 1000;
level = preFixes[offset];
@@ -210,7 +214,7 @@ public class Platform
final int west_y = forward.zOffset * up.xOffset - forward.xOffset * up.zOffset;
final int west_z = forward.xOffset * up.yOffset - forward.yOffset * up.xOffset;
switch( west_x + west_y * 2 + west_z * 3 )
switch ( west_x + west_y * 2 + west_z * 3 )
{
case 1:
return AEPartLocation.EAST;
@@ -237,7 +241,7 @@ public class Platform
final int west_y = forward.getFrontOffsetZ() * up.getFrontOffsetX() - forward.getFrontOffsetX() * up.getFrontOffsetZ();
final int west_z = forward.getFrontOffsetX() * up.getFrontOffsetY() - forward.getFrontOffsetY() * up.getFrontOffsetX();
switch( west_x + west_y * 2 + west_z * 3 )
switch ( west_x + west_y * 2 + west_z * 3 )
{
case 1:
return EnumFacing.EAST;
@@ -271,8 +275,7 @@ public class Platform
{
ce = nextEnum( ce );
}
}
while( !validOptions.contains( ce ) || isNotValidSetting( ce ) );
} while ( !validOptions.contains( ce ) || isNotValidSetting( ce ) );
return ce;
}
@@ -446,7 +449,7 @@ public class Platform
{
if( upAndDown )
{
switch( dir )
switch ( dir )
{
case NORTH:
return AEPartLocation.SOUTH;
@@ -466,7 +469,7 @@ public class Platform
}
else
{
switch( dir )
switch ( dir )
{
case UP:
return AEPartLocation.DOWN;
@@ -519,8 +522,7 @@ public class Platform
final double offset_x = ( getRandomInt() % 32 - 16 ) / 82;
final double offset_y = ( getRandomInt() % 32 - 16 ) / 82;
final double offset_z = ( getRandomInt() % 32 - 16 ) / 82;
final EntityItem ei = new EntityItem( w, 0.5 + offset_x + pos.getX(), 0.5 + offset_y + pos.getY(), 0.2 + offset_z + pos.getZ(), i
.copy() );
final EntityItem ei = new EntityItem( w, 0.5 + offset_x + pos.getX(), 0.5 + offset_y + pos.getY(), 0.2 + offset_z + pos.getZ(), i.copy() );
w.spawnEntity( ei );
}
}
@@ -592,8 +594,7 @@ public class Platform
try
{
ITooltipFlag.TooltipFlags tooltipFlag = Minecraft
.getMinecraft().gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL;
ITooltipFlag.TooltipFlags tooltipFlag = Minecraft.getMinecraft().gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL;
return itemStack.getTooltip( Minecraft.getMinecraft().player, tooltipFlag );
}
catch( final Exception errB )
@@ -764,7 +765,7 @@ public class Platform
public static int MC2MEColor( final int color )
{
switch( color )
switch ( color )
{
case 4: // "blue"
return 0;
@@ -842,10 +843,10 @@ public class Platform
return forward;
}
switch( forward )
switch ( forward )
{
case DOWN:
switch( axis )
switch ( axis )
{
case DOWN:
return forward;
@@ -864,7 +865,7 @@ public class Platform
}
break;
case UP:
switch( axis )
switch ( axis )
{
case NORTH:
return AEPartLocation.WEST;
@@ -879,7 +880,7 @@ public class Platform
}
break;
case NORTH:
switch( axis )
switch ( axis )
{
case UP:
return AEPartLocation.WEST;
@@ -894,7 +895,7 @@ public class Platform
}
break;
case SOUTH:
switch( axis )
switch ( axis )
{
case UP:
return AEPartLocation.EAST;
@@ -909,7 +910,7 @@ public class Platform
}
break;
case EAST:
switch( axis )
switch ( axis )
{
case UP:
return AEPartLocation.NORTH;
@@ -923,7 +924,7 @@ public class Platform
break;
}
case WEST:
switch( axis )
switch ( axis )
{
case UP:
return AEPartLocation.SOUTH;
@@ -944,10 +945,10 @@ public class Platform
public static EnumFacing rotateAround( final EnumFacing forward, final EnumFacing axis )
{
switch( forward )
switch ( forward )
{
case DOWN:
switch( axis )
switch ( axis )
{
case DOWN:
return forward;
@@ -966,7 +967,7 @@ public class Platform
}
break;
case UP:
switch( axis )
switch ( axis )
{
case NORTH:
return EnumFacing.WEST;
@@ -981,7 +982,7 @@ public class Platform
}
break;
case NORTH:
switch( axis )
switch ( axis )
{
case UP:
return EnumFacing.WEST;
@@ -996,7 +997,7 @@ public class Platform
}
break;
case SOUTH:
switch( axis )
switch ( axis )
{
case UP:
return EnumFacing.EAST;
@@ -1011,7 +1012,7 @@ public class Platform
}
break;
case EAST:
switch( axis )
switch ( axis )
{
case UP:
return EnumFacing.NORTH;
@@ -1025,7 +1026,7 @@ public class Platform
break;
}
case WEST:
switch( axis )
switch ( axis )
{
case UP:
return EnumFacing.SOUTH;
@@ -1101,9 +1102,7 @@ public class Platform
final Vec3d vec31 = vec3.addVector( f7 * d3, f6 * d3, f8 * d3 );
final AxisAlignedBB bb = new AxisAlignedBB( Math.min( vec3.x, vec31.x ), Math.min( vec3.y, vec31.y ), Math.min( vec3.z,
vec31.z ), Math.max( vec3.x, vec31.x ), Math.max( vec3.y, vec31.y ), Math.max( vec3.z, vec31.z ) ).grow(
16, 16, 16 );
final AxisAlignedBB bb = new AxisAlignedBB( Math.min( vec3.x, vec31.x ), Math.min( vec3.y, vec31.y ), Math.min( vec3.z, vec31.z ), Math.max( vec3.x, vec31.x ), Math.max( vec3.y, vec31.y ), Math.max( vec3.z, vec31.z ) ).grow( 16, 16, 16 );
Entity entity = null;
double closest = 9999999.0D;
@@ -1249,12 +1248,11 @@ public class Platform
final T leftover = input.copy();
final T split = input.copy();
leftover.decStackSize(itemToAdd);
split.setStackSize(itemToAdd);
leftover.add(cell.injectItems(split, Actionable.MODULATE, src));
leftover.decStackSize( itemToAdd );
split.setStackSize( itemToAdd );
leftover.add( cell.injectItems( split, Actionable.MODULATE, src ) );
src.player().ifPresent( player ->
{
src.player().ifPresent( player -> {
final long diff = original - leftover.getStackSize();
Stats.ItemsInserted.addToPlayer( player, (int) diff );
} );
@@ -1264,8 +1262,7 @@ public class Platform
final T ret = cell.injectItems( input, Actionable.MODULATE, src );
src.player().ifPresent( player ->
{
src.player().ifPresent( player -> {
final long diff = ret == null ? input.getStackSize() : input.getStackSize() - ret.getStackSize();
Stats.ItemsInserted.addToPlayer( player, (int) diff );
} );
@@ -1282,7 +1279,7 @@ public class Platform
return input;
}
@SuppressWarnings( { "rawtypes", "unchecked" } )
@SuppressWarnings( {"rawtypes", "unchecked"} )
public static void postChanges( final IStorageGrid gs, final ItemStack removed, final ItemStack added, final IActionSource src )
{
for( final IStorageChannel<?> chan : AEApi.instance().storage().storageChannels() )
@@ -1361,8 +1358,7 @@ public class Platform
final String locationA = a.getGridBlock().isWorldAccessible() ? a.getGridBlock().getLocation().toString() : "notInWorld";
final String locationB = b.getGridBlock().isWorldAccessible() ? b.getGridBlock().getLocation().toString() : "notInWorld";
AELog.info( "Audit: Node A [isSecure=%b, key=%d, playerID=%d, location={%s}] vs Node B[isSecure=%b, key=%d, playerID=%d, location={%s}]",
a_isSecure, a.getLastSecurityKey(), a.getPlayerID(), locationA, b_isSecure, b.getLastSecurityKey(), b.getPlayerID(), locationB );
AELog.info( "Audit: Node A [isSecure=%b, key=%d, playerID=%d, location={%s}] vs Node B[isSecure=%b, key=%d, playerID=%d, location={%s}]", a_isSecure, a.getLastSecurityKey(), a.getPlayerID(), locationA, b_isSecure, b.getLastSecurityKey(), b.getPlayerID(), locationB );
}
// can't do that son...
@@ -1423,7 +1419,7 @@ public class Platform
float yaw = 0.0f;
// player.yOffset = 1.8f;
switch( side )
switch ( side )
{
case DOWN:
pitch = 90.0f;
@@ -1513,16 +1509,14 @@ public class Platform
}
}
final boolean checkFuzzy = ae_req.getOre().isPresent() || providedTemplate.getItemDamage() == OreDictionary.WILDCARD_VALUE || providedTemplate
.hasTagCompound() || providedTemplate.isItemStackDamageable();
final boolean checkFuzzy = ae_req.getOre().isPresent() || providedTemplate.getItemDamage() == OreDictionary.WILDCARD_VALUE || providedTemplate.hasTagCompound() || providedTemplate.isItemStackDamageable();
if( items != null && checkFuzzy )
{
for( final IAEItemStack x : items )
{
final ItemStack sh = x.getDefinition();
if( ( Platform.itemComparisons().isEqualItemType( providedTemplate, sh ) || ae_req.sameOre( x ) ) && !ItemStack.areItemsEqual( sh,
output ) )
if( ( Platform.itemComparisons().isEqualItemType( providedTemplate, sh ) || ae_req.sameOre( x ) ) && !ItemStack.areItemsEqual( sh, output ) )
{ // Platform.isSameItemType( sh, providedTemplate )
final ItemStack cp = sh.copy();
cp.setCount( 1 );
@@ -1681,4 +1675,9 @@ public class Platform
return isPurified;
}
public static boolean isGTDamageableItem( Item item )
{
return ( isModLoaded( "gregtech" ) && item instanceof IToolItem );
}
}
@@ -1,20 +1,12 @@
package appeng.util.inv;
import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.helpers.NonBlockingItems;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import gregtech.common.items.MetaTool;
import it.unimi.dsi.fastutil.ints.IntSet;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import java.util.Collection;
import java.util.Iterator;
+10 -10
View File
@@ -18,7 +18,6 @@
package appeng.util.item;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
@@ -27,7 +26,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.google.common.primitives.Ints;
import gregtech.common.items.MetaTool;
import gregtech.api.items.IToolItem;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -45,7 +44,7 @@ import appeng.core.Api;
import appeng.util.Platform;
public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack
public class AEItemStack extends AEStack<IAEItemStack> implements IAEItemStack
{
private static final String NBT_STACKSIZE = "Cnt";
private static final String NBT_REQUESTABLE = "Req";
@@ -363,7 +362,7 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
private boolean fuzzyItemStackComparison( ItemStack a, ItemStack b, FuzzyMode mode )
{
if( a.getItem() == b.getItem() && ( a.getItem().isDamageable() || Platform.isModLoaded( "gregtech" ) && a.getItem() instanceof MetaTool ) )
if( a.getItem() == b.getItem() && ( a.getItem().isDamageable() || Platform.isGTDamageableItem( a.getItem() ) ) )
{
if( mode == FuzzyMode.IGNORE_ALL )
{
@@ -371,7 +370,7 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
{
return true;
}
else if( Platform.isModLoaded( "gregtech" ) && a.getItem() instanceof MetaTool )
else if( Platform.isGTDamageableItem( a.getItem() ) )
{
return a.getItemDamage() == b.getItemDamage();
}
@@ -382,9 +381,9 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
{
return a.getItemDamage() > 1 == b.getItemDamage() > 1;
}
else if( Platform.isModLoaded( "gregtech" ) && a.getItem() instanceof MetaTool )
else if( Platform.isGTDamageableItem( a.getItem() ) )
{
return ( (MetaTool) a.getItem() ).getItemDamage( a ) == ( (MetaTool) b.getItem() ).getItemDamage( b );
return ( (IToolItem) a.getItem() ).getItemDamage( a ) == ( (IToolItem) b.getItem() ).getItemDamage( b );
}
}
else
@@ -396,10 +395,10 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
percentDamageOfA = (float) a.getItemDamage() / a.getMaxDamage();
percentDamageOfB = (float) b.getItemDamage() / b.getMaxDamage();
}
else if( Platform.isModLoaded( "gregtech" ) && a.getItem() instanceof MetaTool )
else if( Platform.isGTDamageableItem( a.getItem() ) )
{
percentDamageOfA = (float) ( (MetaTool) a.getItem() ).getItemDamage( a ) / ( (MetaTool) a.getItem() ).getMaxItemDamage( a );
percentDamageOfB = (float) ( (MetaTool) b.getItem() ).getItemDamage( b ) / ( (MetaTool) b.getItem() ).getMaxItemDamage( b );
percentDamageOfA = (float) ( (IToolItem) a.getItem() ).getItemDamage( a ) / ( (IToolItem) a.getItem() ).getMaxItemDamage( a );
percentDamageOfB = (float) ( (IToolItem) b.getItem() ).getItemDamage( b ) / ( (IToolItem) b.getItem() ).getMaxItemDamage( b );
}
return percentDamageOfA > mode.breakPoint == percentDamageOfB > mode.breakPoint;
@@ -408,4 +407,5 @@ public final class AEItemStack extends AEStack<IAEItemStack> implements IAEItemS
return false;
}
}
@@ -25,7 +25,7 @@ import java.util.Map;
import appeng.util.Platform;
import com.google.common.base.Preconditions;
import gregtech.common.items.MetaTool;
import gregtech.api.items.IToolItem;
import net.minecraft.item.ItemStack;
import it.unimi.dsi.fastutil.objects.Object2ObjectAVLTreeMap;
@@ -165,14 +165,14 @@ class FuzzyItemVariantList extends ItemVariantList
*/
static ItemDamageBound makeLowerBound( final ItemStack stack, final FuzzyMode fuzzy )
{
Preconditions.checkState( stack.getItem().isDamageable() || ( Platform.isModLoaded( "gregtech" ) && stack.getItem() instanceof MetaTool ), "Item#isDamageable() has to be true" );
Preconditions.checkState( stack.getItem().isDamageable() || ( Platform.isGTDamageableItem( stack.getItem() ) ), "Item#isDamageable() has to be true" );
int damage;
int maxDamage;
if( Platform.isModLoaded( "gregtech" ) && stack.getItem() instanceof MetaTool )
if( Platform.isGTDamageableItem( stack.getItem() ) )
{
maxDamage = ( (MetaTool) stack.getItem() ).getMaxItemDamage( stack );
damage = ( (MetaTool) stack.getItem() ).getItemDamage( stack );
maxDamage = ( (IToolItem) stack.getItem() ).getMaxItemDamage( stack );
damage = ( (IToolItem) stack.getItem() ).getItemDamage( stack );
}
else
{
@@ -202,7 +202,7 @@ class FuzzyItemVariantList extends ItemVariantList
*/
static ItemDamageBound makeUpperBound( final ItemStack stack, final FuzzyMode fuzzy )
{
Preconditions.checkState( stack.getItem().isDamageable() || ( Platform.isModLoaded( "gregtech" ) && stack.getItem() instanceof MetaTool ), "Item#isDamageable() has to be true" );
Preconditions.checkState( stack.getItem().isDamageable() || ( Platform.isGTDamageableItem( stack.getItem() ) ), "Item#isDamageable() has to be true" );
int damage;
if( fuzzy == FuzzyMode.IGNORE_ALL )
@@ -212,10 +212,10 @@ class FuzzyItemVariantList extends ItemVariantList
else
{
int maxDamage;
if( Platform.isModLoaded( "gregtech" ) && stack.getItem() instanceof MetaTool )
if( Platform.isGTDamageableItem( stack.getItem() ) )
{
maxDamage = ( (MetaTool) stack.getItem() ).getMaxItemDamage( stack );
damage = ( (MetaTool) stack.getItem() ).getItemDamage( stack );
maxDamage = ( (IToolItem) stack.getItem() ).getMaxItemDamage( stack );
damage = ( (IToolItem) stack.getItem() ).getItemDamage( stack );
}
else
{
+1 -2
View File
@@ -26,7 +26,6 @@ import java.util.NoSuchElementException;
import java.util.concurrent.atomic.AtomicInteger;
import appeng.util.Platform;
import gregtech.common.items.MetaTool;
import net.minecraft.item.Item;
import it.unimi.dsi.fastutil.objects.Reference2ObjectMap;
@@ -175,7 +174,7 @@ public final class ItemList implements IItemList<IAEItemStack>
private ItemVariantList makeRecordMap( Item item )
{
if( item.isDamageable() || ( Platform.isModLoaded( "gregtech" ) && item instanceof MetaTool ) )
if( item.isDamageable() || Platform.isGTDamageableItem( item ) )
{
return new FuzzyItemVariantList();
}