Removed Inscriber Recipe Registry

Fixed Inscriber TESR rendering and added a small easing function
This commit is contained in:
Sebastian Hartte
2020-06-14 11:27:24 +02:00
parent 8e1d90a873
commit 9599a31893
15 changed files with 258 additions and 990 deletions
@@ -0,0 +1,144 @@
package appeng.tile.misc;
import appeng.api.AEApi;
import appeng.api.definitions.IComparableDefinition;
import appeng.api.features.InscriberProcessType;
import appeng.core.AppEng;
import appeng.recipes.handlers.InscriberRecipe;
import com.google.common.collect.Iterables;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import javax.annotation.Nullable;
import java.util.Collection;
/**
* This class indexes all inscriber recipes to find valid inputs for the top and bottom
* optional slots. This speeds up checks whether inputs for those two slots are valid.
*/
public final class InscriberRecipes {
public static final ResourceLocation NAMEPLATE_RECIPE_ID = new ResourceLocation(AppEng.MOD_ID, "nameplate");
private InscriberRecipes() {
}
/**
* Returns an unmodifiable view of all registered inscriber recipes.
*/
public static Iterable<InscriberRecipe> getRecipes(World world) {
Collection<IRecipe<IInventory>> unfilteredRecipes = world.getRecipeManager().getRecipes(InscriberRecipe.TYPE).values();
return Iterables.filter(unfilteredRecipes, InscriberRecipe.class);
}
@Nullable
public static InscriberRecipe findRecipe(World world, ItemStack input, ItemStack plateA, ItemStack plateB, boolean supportNamePress) {
if (supportNamePress) {
IComparableDefinition namePress = AEApi.instance().definitions().materials().namePress();
boolean isNameA = namePress.isSameAs(plateA);
boolean isNameB = namePress.isSameAs(plateB);
if ((isNameA && isNameB) || isNameA && plateB.isEmpty()) {
return makeNamePressRecipe(input, plateA, plateB);
} else if (plateA.isEmpty() && isNameB) {
return makeNamePressRecipe(input, plateB, plateA);
}
}
for( final InscriberRecipe recipe : getRecipes(world) )
{
// The recipe can be flipped at will
final boolean matchA = recipe.getTopOptional().test(plateA) && recipe.getBottomOptional().test(plateB);
final boolean matchB = recipe.getTopOptional().test(plateB) && recipe.getBottomOptional().test(plateA);
if( matchA || matchB )
{
if (recipe.getMiddleInput().test(input)) {
return recipe;
}
}
}
return null;
}
private static InscriberRecipe makeNamePressRecipe( ItemStack input, ItemStack plateA, ItemStack plateB )
{
String name = "";
if( !plateA.isEmpty() )
{
final CompoundNBT tag = plateA.getOrCreateTag();
name += tag.getString( "InscribeName" );
}
if( !plateB.isEmpty() )
{
final CompoundNBT tag = plateB.getOrCreateTag();
name += " " + tag.getString( "InscribeName" );
}
final Ingredient startingItem = Ingredient.fromStacks(input.copy());
final ItemStack renamedItem = input.copy();
final CompoundNBT display = renamedItem.getOrCreateChildTag( "display" );
if( !name.isEmpty() )
{
display.putString("Name", name);
}
else
{
display.remove( "Name" );
}
final InscriberProcessType type = InscriberProcessType.INSCRIBE;
return new InscriberRecipe(
NAMEPLATE_RECIPE_ID,
"",
startingItem,
renamedItem,
plateA.isEmpty() ? Ingredient.EMPTY : Ingredient.fromStacks(plateA),
plateB.isEmpty() ? Ingredient.EMPTY : Ingredient.fromStacks(plateB),
type
);
}
/**
* Checks if there is an inscriber recipe that supports the given combination of top/bottom presses.
* Both the given combination and the reverse will be searched.
*/
public static boolean isValidOptionalIngredientCombination(World world, ItemStack pressA, ItemStack pressB) {
for (InscriberRecipe recipe : getRecipes(world)) {
if (recipe.getTopOptional().test(pressA) && recipe.getBottomOptional().test(pressB)
|| recipe.getTopOptional().test(pressB) && recipe.getBottomOptional().test(pressA))
{
return true;
}
}
return false;
}
/**
* Checks if there is an inscriber recipe that would use the given item stack as an optional ingredient.
* Bottom and top can be used interchangeably here, because the inscriber will flip the recipe if needed.
*/
public static boolean isValidOptionalIngredient(World world, ItemStack is) {
for (InscriberRecipe recipe : getRecipes(world)) {
if (recipe.getTopOptional().test(is)
|| recipe.getBottomOptional().test(is))
{
return true;
}
}
return false;
}
}
+17 -131
View File
@@ -26,7 +26,7 @@ import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.google.common.collect.Lists;
import appeng.recipes.handlers.InscriberRecipe;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
@@ -42,10 +42,7 @@ import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
import appeng.api.config.Upgrades;
import appeng.api.definitions.IComparableDefinition;
import appeng.api.definitions.ITileDefinition;
import appeng.api.features.IInscriberRecipe;
import appeng.api.features.IInscriberRecipeBuilder;
import appeng.api.features.InscriberProcessType;
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.networking.IGridNode;
@@ -65,7 +62,6 @@ import appeng.tile.grid.AENetworkPowerTile;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import appeng.util.inv.InvOperation;
import appeng.util.inv.WrapperChainedItemHandler;
import appeng.util.inv.WrapperFilteredItemHandler;
@@ -98,7 +94,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
private final IItemHandler bottomItemHandlerExtern;
private final IItemHandler sideItemHandlerExtern;
private IInscriberRecipe cachedTask = null;
private InscriberRecipe cachedTask = null;
private final IItemHandlerModifiable inv = new WrapperChainedItemHandler( this.topItemHandler, this.bottomItemHandler, this.sideItemHandler );
@@ -278,79 +274,24 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
}
@Nullable
public IInscriberRecipe getTask()
public InscriberRecipe getTask()
{
if( this.cachedTask == null )
if ( this.cachedTask == null && world != null )
{
this.cachedTask = this.getTask( this.sideItemHandler.getStackInSlot( 0 ), this.topItemHandler.getStackInSlot( 0 ),
this.bottomItemHandler.getStackInSlot( 0 ) );
ItemStack input = this.sideItemHandler.getStackInSlot(0);
ItemStack plateA = this.topItemHandler.getStackInSlot(0);
ItemStack plateB = this.bottomItemHandler.getStackInSlot(0);
// If the player somehow managed to insert more than one item, we bail here
if( input.getCount() > 1 || plateA.getCount() > 1 || plateB.getCount() > 1 )
{
return null;
}
this.cachedTask = InscriberRecipes.findRecipe( world, input, plateA, plateB, true);
}
return this.cachedTask;
}
@Nullable
private IInscriberRecipe getTask( final ItemStack input, final ItemStack plateA, final ItemStack plateB )
{
if( input.isEmpty() || input.getCount() > 1 )
{
return null;
}
if( !plateA.isEmpty() && plateA.getCount() > 1 )
{
return null;
}
if( !plateB.isEmpty() && plateB.getCount() > 1 )
{
return null;
}
final IComparableDefinition namePress = AEApi.instance().definitions().materials().namePress();
final boolean isNameA = namePress.isSameAs( plateA );
final boolean isNameB = namePress.isSameAs( plateB );
if( ( isNameA && isNameB ) || isNameA && plateB.isEmpty() )
{
return this.makeNamePressRecipe( input, plateA, plateB );
}
else if( plateA.isEmpty() && isNameB )
{
return this.makeNamePressRecipe( input, plateB, plateA );
}
for( final IInscriberRecipe recipe : AEApi.instance().registries().inscriber().getRecipes() )
{
final boolean matchA = ( plateA.isEmpty() && !recipe.getTopOptional().isPresent() ) || ( Platform.itemComparisons()
.isSameItem( plateA,
recipe.getTopOptional().orElse( ItemStack.EMPTY ) ) ) && // and...
( ( plateB.isEmpty() && !recipe.getBottomOptional().isPresent() ) || ( Platform.itemComparisons()
.isSameItem( plateB,
recipe.getBottomOptional().orElse( ItemStack.EMPTY ) ) ) );
final boolean matchB = ( plateB.isEmpty() && !recipe.getTopOptional().isPresent() ) || ( Platform.itemComparisons()
.isSameItem( plateB,
recipe.getTopOptional().orElse( ItemStack.EMPTY ) ) ) && // and...
( ( plateA.isEmpty() && !recipe.getBottomOptional().isPresent() ) || ( Platform.itemComparisons()
.isSameItem( plateA,
recipe.getBottomOptional().orElse( ItemStack.EMPTY ) ) ) );
if( matchA || matchB )
{
for( final ItemStack option : recipe.getInputs() )
{
if( Platform.itemComparisons().isSameItem( input, option ) )
{
return recipe;
}
}
}
}
return null;
}
@Override
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
{
@@ -359,7 +300,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
this.finalStep++;
if( this.finalStep == 8 )
{
final IInscriberRecipe out = this.getTask();
final InscriberRecipe out = this.getTask();
if( out != null )
{
final ItemStack outputCopy = out.getOutput().copy();
@@ -425,7 +366,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
if( this.getProcessingTime() > this.getMaxProcessingTime() )
{
this.setProcessingTime( this.getMaxProcessingTime() );
final IInscriberRecipe out = this.getTask();
final InscriberRecipe out = this.getTask();
if( out != null )
{
final ItemStack outputCopy = out.getOutput().copy();
@@ -527,54 +468,6 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
this.processingTime = processingTime;
}
private IInscriberRecipe makeNamePressRecipe( ItemStack input, ItemStack plateA, ItemStack plateB )
{
String name = "";
if( !plateA.isEmpty() )
{
final CompoundNBT tag = plateA.getOrCreateTag();
name += tag.getString( "InscribeName" );
}
if( !plateB.isEmpty() )
{
final CompoundNBT tag = plateB.getOrCreateTag();
name += " " + tag.getString( "InscribeName" );
}
final ItemStack startingItem = input.copy();
final ItemStack renamedItem = input.copy();
final CompoundNBT display = renamedItem.getOrCreateChildTag( "display" );
if( !name.isEmpty() )
{
display.putString("Name", name);
}
else
{
display.remove( "Name" );
}
final List<ItemStack> inputs = Lists.newArrayList( startingItem );
final InscriberProcessType type = InscriberProcessType.INSCRIBE;
final IInscriberRecipeBuilder builder = AEApi.instance().registries().inscriber().builder();
builder.withInputs( inputs ).withOutput( renamedItem ).withProcessType( type );
if( !plateA.isEmpty() )
{
builder.withTopOptional( plateA );
}
if( !plateB.isEmpty() )
{
builder.withBottomOptional( plateB );
}
return builder.build();
}
/**
* This is an item handler that exposes the inscribers inventory while providing simulation capabilities that do not
* reset the progress if there's already an item in a slot. Previously, the progress of the inscriber was reset when
@@ -613,14 +506,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
{
return true;
}
for( final ItemStack optionals : AEApi.instance().registries().inscriber().getOptionals() )
{
if( Platform.itemComparisons().isSameItem( stack, optionals ) )
{
return true;
}
}
return false;
return InscriberRecipes.isValidOptionalIngredient(getWorld(), stack);
}
return true;
}