Closes #1054: Adds an Inscriber API for Developers
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
package appeng.core.features.registries;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.features.IInscriberRecipe;
|
||||
import appeng.api.features.IInscriberRecipeBuilder;
|
||||
import appeng.api.features.IInscriberRegistry;
|
||||
import appeng.api.features.InscriberProcessType;
|
||||
import appeng.core.features.registries.entries.InscriberRecipe;
|
||||
|
||||
|
||||
/**
|
||||
* @author thatsIch
|
||||
* @version rv2
|
||||
* @since rv2
|
||||
*/
|
||||
public final class InscriberRegistry implements IInscriberRegistry
|
||||
{
|
||||
private final List<IInscriberRecipe> recipes;
|
||||
private final Set<ItemStack> optionals;
|
||||
private final Set<ItemStack> inputs;
|
||||
|
||||
public InscriberRegistry()
|
||||
{
|
||||
this.inputs = new HashSet<ItemStack>();
|
||||
this.optionals = new HashSet<ItemStack>();
|
||||
this.recipes = new ArrayList<IInscriberRecipe>();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<IInscriberRecipe> getRecipes()
|
||||
{
|
||||
return this.recipes;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<ItemStack> getOptionals()
|
||||
{
|
||||
return this.optionals;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Set<ItemStack> getInputs()
|
||||
{
|
||||
return this.inputs;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IInscriberRecipeBuilder builder()
|
||||
{
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRecipe( IInscriberRecipe recipe )
|
||||
{
|
||||
if( recipe == null )
|
||||
throw new IllegalArgumentException( "Tried to add an invalid (null) inscriber recipe to the registry." );
|
||||
|
||||
this.recipes.add( recipe );
|
||||
|
||||
this.optionals.addAll( recipe.getTopOptional().asSet() );
|
||||
this.optionals.addAll( recipe.getBottomOptional().asSet() );
|
||||
|
||||
this.inputs.addAll( recipe.getInputs() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeRecipe( IInscriberRecipe toBeRemovedRecipe )
|
||||
{
|
||||
for( final Iterator<IInscriberRecipe> iterator = this.recipes.iterator(); iterator.hasNext(); )
|
||||
{
|
||||
final IInscriberRecipe recipe = iterator.next();
|
||||
if( recipe.equals( toBeRemovedRecipe ) )
|
||||
{
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal {@link IInscriberRecipeBuilder} implementation.
|
||||
* Needs to be adapted to represent a correct {@link IInscriberRecipe}
|
||||
*/
|
||||
private static final class Builder implements IInscriberRecipeBuilder
|
||||
{
|
||||
private List<ItemStack> inputs;
|
||||
private ItemStack output;
|
||||
private ItemStack topOptional;
|
||||
private ItemStack bottomOptional;
|
||||
private InscriberProcessType type;
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Builder withInputs( @Nonnull Collection<ItemStack> inputs )
|
||||
{
|
||||
this.inputs = new ArrayList<ItemStack>( inputs.size() );
|
||||
this.inputs.addAll( inputs );
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Builder withOutput( @Nonnull ItemStack output )
|
||||
{
|
||||
this.output = output;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Builder withTopOptional( @Nonnull ItemStack topOptional )
|
||||
{
|
||||
this.topOptional = topOptional;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Builder withBottomOptional( @Nonnull ItemStack bottomOptional )
|
||||
{
|
||||
this.bottomOptional = bottomOptional;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public Builder withProcessType( @Nonnull InscriberProcessType type )
|
||||
{
|
||||
this.type = type;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public IInscriberRecipe build()
|
||||
{
|
||||
if( this.inputs == null )
|
||||
throw new IllegalStateException( "Input must be defined." );
|
||||
if( this.inputs.size() == 0 )
|
||||
throw new IllegalStateException( "Input must have a size." );
|
||||
if( this.output == null )
|
||||
throw new IllegalStateException( "Output must be defined." );
|
||||
if ( this.topOptional == null && this.bottomOptional == null )
|
||||
throw new IllegalStateException( "One optional must be defined." );
|
||||
if ( this.type == null )
|
||||
throw new IllegalStateException( "Process type must be defined." );
|
||||
|
||||
return new InscriberRecipe( this.inputs, this.output, this.topOptional, this.bottomOptional, this.type );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ package appeng.core.features.registries;
|
||||
|
||||
|
||||
import appeng.api.features.IGrinderRegistry;
|
||||
import appeng.api.features.IInscriberRegistry;
|
||||
import appeng.api.features.ILocatableRegistry;
|
||||
import appeng.api.features.IMatterCannonAmmoRegistry;
|
||||
import appeng.api.features.IP2PTunnelRegistry;
|
||||
@@ -35,74 +36,88 @@ import appeng.api.storage.ICellRegistry;
|
||||
import appeng.api.storage.IExternalStorageRegistry;
|
||||
|
||||
|
||||
/**
|
||||
* represents all registries
|
||||
*
|
||||
* @author AlgorithmX2
|
||||
* @author thatsIch
|
||||
* @version rv2
|
||||
* @since rv0
|
||||
*/
|
||||
public class RegistryContainer implements IRegistryContainer
|
||||
{
|
||||
|
||||
private final GrinderRecipeManager GrinderRecipes = new GrinderRecipeManager();
|
||||
private final ExternalStorageRegistry ExternalStorageHandlers = new ExternalStorageRegistry();
|
||||
private final CellRegistry CellRegistry = new CellRegistry();
|
||||
private final LocatableRegistry LocatableRegistry = new LocatableRegistry();
|
||||
private final SpecialComparisonRegistry SpecialComparisonRegistry = new SpecialComparisonRegistry();
|
||||
private final WirelessRegistry WirelessRegistry = new WirelessRegistry();
|
||||
private final GridCacheRegistry GridCacheRegistry = new GridCacheRegistry();
|
||||
private final P2PTunnelRegistry P2PRegistry = new P2PTunnelRegistry();
|
||||
private final MovableTileRegistry MovableReg = new MovableTileRegistry();
|
||||
private final MatterCannonAmmoRegistry matterCannonReg = new MatterCannonAmmoRegistry();
|
||||
private final PlayerRegistry playerRegistry = new PlayerRegistry();
|
||||
private final IGrinderRegistry grinder = new GrinderRecipeManager();
|
||||
private final IInscriberRegistry inscriber = new InscriberRegistry();
|
||||
private final IExternalStorageRegistry storage = new ExternalStorageRegistry();
|
||||
private final ICellRegistry cell = new CellRegistry();
|
||||
private final ILocatableRegistry locatable = new LocatableRegistry();
|
||||
private final ISpecialComparisonRegistry comparison = new SpecialComparisonRegistry();
|
||||
private final IWirelessTermRegistry wireless = new WirelessRegistry();
|
||||
private final IGridCacheRegistry gridCache = new GridCacheRegistry();
|
||||
private final IP2PTunnelRegistry p2ptunnel = new P2PTunnelRegistry();
|
||||
private final IMovableRegistry movable = new MovableTileRegistry();
|
||||
private final IMatterCannonAmmoRegistry matterCannonReg = new MatterCannonAmmoRegistry();
|
||||
private final IPlayerRegistry playerRegistry = new PlayerRegistry();
|
||||
private final IRecipeHandlerRegistry recipeReg = new RecipeHandlerRegistry();
|
||||
|
||||
@Override
|
||||
public IMovableRegistry movable()
|
||||
{
|
||||
return this.MovableReg;
|
||||
return this.movable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridCacheRegistry gridCache()
|
||||
{
|
||||
return this.GridCacheRegistry;
|
||||
return this.gridCache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IExternalStorageRegistry externalStorage()
|
||||
{
|
||||
return this.ExternalStorageHandlers;
|
||||
return this.storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpecialComparisonRegistry specialComparison()
|
||||
{
|
||||
return this.SpecialComparisonRegistry;
|
||||
return this.comparison;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWirelessTermRegistry wireless()
|
||||
{
|
||||
return this.WirelessRegistry;
|
||||
return this.wireless;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICellRegistry cell()
|
||||
{
|
||||
return this.CellRegistry;
|
||||
return this.cell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGrinderRegistry grinder()
|
||||
{
|
||||
return this.GrinderRecipes;
|
||||
return this.grinder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInscriberRegistry inscriber()
|
||||
{
|
||||
return this.inscriber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILocatableRegistry locatable()
|
||||
{
|
||||
return this.LocatableRegistry;
|
||||
return this.locatable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IP2PTunnelRegistry p2pTunnel()
|
||||
{
|
||||
return this.P2PRegistry;
|
||||
return this.p2ptunnel;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package appeng.core.features.registries.entries;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.features.InscriberProcessType;
|
||||
|
||||
|
||||
/**
|
||||
* inscribe recipes do not use up the provided optional upon craft
|
||||
*
|
||||
* @author thatsIch
|
||||
* @version rv2
|
||||
* @since rv2
|
||||
*/
|
||||
public class InscriberInscribeRecipe extends InscriberRecipe
|
||||
{
|
||||
public InscriberInscribeRecipe( @Nonnull Collection<ItemStack> inputs, @Nonnull ItemStack output, @Nullable ItemStack top, @Nullable ItemStack bot )
|
||||
{
|
||||
super( inputs, output, top, bot, InscriberProcessType.Inscribe );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package appeng.core.features.registries.entries;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import appeng.api.features.IInscriberRecipe;
|
||||
import appeng.api.features.InscriberProcessType;
|
||||
|
||||
|
||||
/**
|
||||
* Basic inscriber recipe
|
||||
*
|
||||
* @author thatsIch
|
||||
* @version rv2
|
||||
* @since rv2
|
||||
*/
|
||||
public class InscriberRecipe implements IInscriberRecipe
|
||||
{
|
||||
@Nonnull
|
||||
private final List<ItemStack> inputs;
|
||||
|
||||
@Nonnull
|
||||
private final ItemStack output;
|
||||
|
||||
@Nonnull
|
||||
private final Optional<ItemStack> maybeTop;
|
||||
|
||||
@Nonnull
|
||||
private final Optional<ItemStack> maybeBot;
|
||||
|
||||
@Nonnull
|
||||
private final InscriberProcessType type;
|
||||
|
||||
public InscriberRecipe( @Nonnull Collection<ItemStack> inputs, @Nonnull ItemStack output, @Nullable ItemStack top, @Nullable ItemStack bot, @Nonnull InscriberProcessType type )
|
||||
{
|
||||
this.inputs = new ArrayList<ItemStack>( inputs.size() );
|
||||
this.inputs.addAll( inputs );
|
||||
|
||||
this.output = output;
|
||||
this.maybeTop = Optional.fromNullable( top );
|
||||
this.maybeBot = Optional.fromNullable( bot );
|
||||
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public final List<ItemStack> getInputs()
|
||||
{
|
||||
return this.inputs;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public final ItemStack getOutput()
|
||||
{
|
||||
return this.output;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public final Optional<ItemStack> getTopOptional()
|
||||
{
|
||||
return this.maybeTop;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public final Optional<ItemStack> getBottomOptional()
|
||||
{
|
||||
return this.maybeBot;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public final InscriberProcessType getProcessType()
|
||||
{
|
||||
return this.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if( this == o )
|
||||
return true;
|
||||
if( !(o instanceof IInscriberRecipe) )
|
||||
return false;
|
||||
|
||||
IInscriberRecipe that = (IInscriberRecipe) o;
|
||||
|
||||
if( !this.inputs.equals( that.getInputs() ) )
|
||||
return false;
|
||||
if( !this.output.equals( that.getOutput() ) )
|
||||
return false;
|
||||
if( !this.maybeTop.equals( that.getTopOptional() ) )
|
||||
return false;
|
||||
if( !this.maybeBot.equals( that.getBottomOptional()) )
|
||||
return false;
|
||||
return this.type == that.getProcessType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result = this.inputs.hashCode();
|
||||
result = 31 * result + this.output.hashCode();
|
||||
result = 31 * result + this.maybeTop.hashCode();
|
||||
result = 31 * result + this.maybeBot.hashCode();
|
||||
result = 31 * result + this.type.hashCode();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user