Added config for auto crafting of substitutions

Change missing items information to a packet (missing localization stuff yet)
This commit is contained in:
PrototypeTrousers
2022-04-11 02:00:31 -03:00
parent a289dec832
commit 4b6fbf68b6
6 changed files with 138 additions and 230 deletions
+7 -10
View File
@@ -19,16 +19,6 @@
package appeng.crafting;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
import appeng.me.cache.GridStorageCache;
import com.google.common.base.Stopwatch;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.networking.IGrid;
@@ -47,6 +37,13 @@ import appeng.api.storage.data.IItemList;
import appeng.api.util.DimensionalCoord;
import appeng.core.AELog;
import appeng.hooks.TickHandler;
import appeng.me.cache.GridStorageCache;
import com.google.common.base.Stopwatch;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
public class CraftingJob implements Runnable, ICraftingJob
@@ -19,17 +19,9 @@
package appeng.crafting;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import appeng.api.config.FuzzyMode;
import appeng.util.Platform;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.security.IActionSource;
@@ -41,7 +33,6 @@ import appeng.core.sync.packets.PacketInformPlayer;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.util.Platform;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Optional;
@@ -132,32 +123,37 @@ public class CraftingTreeNode
{
Collection<IAEItemStack> itemList = new ArrayList<>();
if( this.what.getItem().isDamageable() || Platform.isGTDamageableItem( this.what.getItem() ) )
{
itemList.addAll( inventoryList.findFuzzy( this.what, FuzzyMode.IGNORE_ALL ) );
boolean damageableItem = this.what.getItem().isDamageable() || Platform.isGTDamageableItem( this.what.getItem() );
if( this.parent.details.canSubstitute() )
if( this.parent.details.canSubstitute() )
{
for( IAEItemStack subs : this.parent.details.getSubstituteInputs( this.slot ) )
{
for( IAEItemStack is : inventoryList )
if( damageableItem )
{
if( is.fuzzyComparison( this.what, FuzzyMode.IGNORE_ALL ) )
{
itemList.add( is );
}
itemList.addAll( inventoryList.findFuzzy( subs, FuzzyMode.IGNORE_ALL ) );
}
subs = inventoryList.findPrecise( subs );
if( subs != null )
{
itemList.add( subs );
}
}
}
else
{
final IAEItemStack item = inventoryList.findPrecise( this.what );
if( item != null )
{
itemList.add( item );
}
if( this.parent.details.canSubstitute() )
if( damageableItem )
{
itemList.addAll( inventoryList.findFuzzy( this.what, FuzzyMode.IGNORE_ALL ) );
}
else
{
final IAEItemStack item = inventoryList.findPrecise( this.what );
if( item != null )
{
itemList.add( item );
}
}
}
for( IAEItemStack fuzz : itemList )
@@ -374,11 +370,11 @@ public class CraftingTreeNode
{
if( ex == null )
{
NetworkHandler.instance().sendTo( new PacketInformPlayer( i ), (EntityPlayerMP) src.player().get() );
NetworkHandler.instance().sendTo( new PacketInformPlayer( i, null, PacketInformPlayer.InfoType.NO_ITEMS_EXTRACTED ), (EntityPlayerMP) src.player().get() );
}
else
{
NetworkHandler.instance().sendTo( new PacketInformPlayer( ex, i ), (EntityPlayerMP) src.player().get() );
NetworkHandler.instance().sendTo( new PacketInformPlayer( ex, i, PacketInformPlayer.InfoType.PARTIAL_ITEM_EXTRACTION ), (EntityPlayerMP) src.player().get() );
}
}
catch( IOException e )
@@ -19,25 +19,24 @@
package appeng.crafting;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import appeng.api.config.FuzzyMode;
import appeng.util.item.AEItemStack;
import com.google.common.collect.ImmutableCollection;
import it.unimi.dsi.fastutil.objects.Object2LongArrayMap;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import appeng.api.config.Actionable;
import appeng.api.networking.crafting.ICraftingGrid;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.core.AEConfig;
import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import com.google.common.collect.ImmutableCollection;
import it.unimi.dsi.fastutil.objects.Object2LongArrayMap;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
public class CraftingTreeProcess
@@ -92,12 +91,13 @@ public class CraftingTreeProcess
}
long wantedSize = part.getStackSize();
IAEItemStack found;
long remaining = 0;
long requestAmount = 0;
if( wantedSize > 0 )
if( AEConfig.instance().getEnableCraftingSubstitutes() )
{
IAEItemStack found;
long remaining;
long requestAmount;
if( details.canSubstitute() )
{
for( IAEItemStack subs : details.getSubstituteInputs( x ) )
@@ -110,7 +110,7 @@ public class CraftingTreeProcess
}
else
{
remaining = 0;
continue;
}
if( remaining > 0 )
@@ -127,7 +127,8 @@ public class CraftingTreeProcess
wantedSize -= remaining;
}
subs = subs.copy().setStackSize( requestAmount );
this.nodes.put( new CraftingTreeNode( cc, job, subs, this, x, depth + 1 ), requestAmount );
CraftingTreeNode node = new CraftingTreeNode( cc, job, subs, this, x, depth + 1 );
this.nodes.put( node, requestAmount );
if( wantedSize == 0 )
{
break;
@@ -143,6 +144,10 @@ public class CraftingTreeProcess
{
remaining = found.getStackSize();
}
else
{
continue;
}
if( remaining > 0 )
{
@@ -161,61 +166,47 @@ public class CraftingTreeProcess
this.nodes.put( new CraftingTreeNode( cc, job, part, this, x, depth + 1 ), requestAmount );
}
}
}
if( wantedSize > 0 )
{
if( details.canSubstitute() && cc.getCraftingFor( part, details, x, world ).isEmpty() )
if( wantedSize > 0 )
{
for( IAEItemStack subs : details.getSubstituteInputs( x ) )
if( details.canSubstitute() && cc.getCraftingFor( part, details, x, world ).isEmpty() )
{
if( subs.fuzzyComparison( part, FuzzyMode.IGNORE_ALL ) )
//try to order the crafting of a substitute
ICraftingPatternDetails prioritizedPattern = null;
IAEItemStack prioritizedIAE = null;
for( IAEItemStack subs : details.getSubstituteInputs( x ) )
{
wantedSize -= 1;
this.nodes.put( new CraftingTreeNode( cc, job, subs.copy().setStackSize( 1 ), this, x, depth + 1 ), 1 );
if( wantedSize == 0 )
{
break;
}
}
}
//try to order the crafting of a substitute
ICraftingPatternDetails prioritizedPattern = null;
IAEItemStack prioritizedIAE = null;
for( IAEItemStack subs : details.getSubstituteInputs( x ) )
{
if( subs.equals( part ) )
{
continue;
}
ImmutableCollection<ICraftingPatternDetails> detailCollection = cc.getCraftingFor( subs, details, x, world );
ImmutableCollection<ICraftingPatternDetails> detailCollection = cc.getCraftingFor( subs, details, x, world );
for( ICraftingPatternDetails sp : detailCollection )
{
if( prioritizedPattern == null )
for( ICraftingPatternDetails sp : detailCollection )
{
prioritizedPattern = sp;
prioritizedIAE = subs;
}
else
{
if( sp.getPriority() > prioritizedPattern.getPriority() )
if( prioritizedPattern == null )
{
prioritizedPattern = sp;
prioritizedIAE = subs;
}
else
{
if( sp.getPriority() > prioritizedPattern.getPriority() )
{
prioritizedPattern = sp;
}
}
}
}
if( prioritizedIAE != null )
{
this.nodes.put( new CraftingTreeNode( cc, job, prioritizedIAE.copy(), this, x, depth + 1 ), wantedSize );
wantedSize = 0;
break;
if( prioritizedIAE != null )
{
subs = subs.copy().setStackSize( wantedSize );
CraftingTreeNode node = new CraftingTreeNode( cc, job, subs, this, x, depth + 1 );
this.nodes.put( node, wantedSize );
wantedSize = 0;
break;
}
}
}
}
}
if( wantedSize > 0 )
{
part = part.copy();
part = part.copy().setStackSize( wantedSize );
// use the first slot...
this.nodes.put( new CraftingTreeNode( cc, job, part, this, x, depth + 1 ), wantedSize );
wantedSize = 0;
@@ -318,11 +318,11 @@ public class MECraftingInventory implements IMEInventory<IAEItemStack>
{
if( result == null )
{
NetworkHandler.instance().sendTo( new PacketInformPlayer( extra ), (EntityPlayerMP) src.player().get() );
NetworkHandler.instance().sendTo( new PacketInformPlayer( extra, null, PacketInformPlayer.InfoType.NO_ITEMS_EXTRACTED ), (EntityPlayerMP) src.player().get() );
}
else
{
NetworkHandler.instance().sendTo( new PacketInformPlayer( extra, result ), (EntityPlayerMP) src.player().get() );
NetworkHandler.instance().sendTo( new PacketInformPlayer( extra, result, PacketInformPlayer.InfoType.PARTIAL_ITEM_EXTRACTION ), (EntityPlayerMP) src.player().get() );
}
}
catch( IOException e )