Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Universal Autocrafting #439

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/api/java/appeng/api/IAppEngApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import appeng.api.parts.IPartHelper;
import appeng.api.storage.IStorageHelper;
import appeng.api.util.IClientHelper;
import appeng.api.util.IDeprecationHelper;


@AEInjectable
Expand Down Expand Up @@ -66,4 +67,9 @@ public interface IAppEngApi
*/
IClientHelper client();

}
/**
* @return A helper for bridging the gap between old and new API shapes.
*/
IDeprecationHelper deprecation();

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,23 @@
package appeng.api.implementations.tiles;


import appeng.api.AEApi;
import appeng.api.networking.crafting.ICraftingInventory;
import appeng.api.storage.channels.IItemStorageChannel;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;

import appeng.api.networking.crafting.ICraftingPatternDetails;


public interface ICraftingMachine
/**
* A machine capable of receiving item autocrafting jobs from an interface.
*
* @deprecated implement and use {@link IUnivCraftingMachine} instead.
*/
@Deprecated
public interface ICraftingMachine extends IUnivCraftingMachine
{

/**
Expand All @@ -44,11 +54,24 @@ public interface ICraftingMachine
*/
boolean pushPattern( ICraftingPatternDetails patternDetails, InventoryCrafting table, EnumFacing ejectionDirection );

/**
* check if the crafting machine is accepting pushes via pushPattern, if this is false, all calls to push will fail,
* you can try inserting into the inventory instead.
*
* @return true, if pushPattern can complete, if its false push will always be false.
*/
boolean acceptsPlans();
@Override
default boolean pushPattern( final ICraftingPatternDetails patternDetails, final ICraftingInventory table, final EnumFacing ejectionDirection )
{
final InventoryCrafting ic = AEApi.instance().deprecation().createFakeCraftingInventory(table.getWidth(), table.getHeight());
if ( !this.pushPattern(patternDetails, ic, ejectionDirection) )
{
return false;
}

final IItemStorageChannel channel = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class);
for ( int i = 0; i < ic.getSizeInventory(); i++ )
{
final ItemStack stack = ic.getStackInSlot(i);
if ( !stack.isEmpty() )
{
table.setStackInSlot(i, channel.createStack(stack));
}
}
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2013 AlgorithmX2
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package appeng.api.implementations.tiles;


import appeng.api.networking.crafting.ICraftingInventory;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import net.minecraft.util.EnumFacing;


/**
* A machine capable of receiving autocrafting jobs from an interface.
*/
public interface IUnivCraftingMachine
{

/**
* inserts a crafting plan, and the necessary items into the crafting machine.
*
* @param patternDetails details of pattern
* @param table crafting table
* @param ejectionDirection ejection direction
*
* @return if it was accepted, all or nothing.
*/
boolean pushPattern( ICraftingPatternDetails patternDetails, ICraftingInventory table, EnumFacing ejectionDirection );

/**
* check if the crafting machine is accepting pushes via pushPattern, if this is false, all calls to push will fail,
* you can try inserting into the inventory instead.
*
* @return true, if pushPattern can complete, if its false push will always be false.
*/
boolean acceptsPlans();
}
32 changes: 29 additions & 3 deletions src/api/java/appeng/api/networking/crafting/ICraftingCPU.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@
package appeng.api.networking.crafting;


import appeng.api.AEApi;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.networking.storage.IUnivMonitor;
import appeng.api.storage.channels.IItemStorageChannel;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack;
import appeng.api.util.IExAEStack;

import javax.annotation.Nullable;


public interface ICraftingCPU extends IBaseMonitor<IAEItemStack>
public interface ICraftingCPU extends IUnivMonitor
{

/**
Expand Down Expand Up @@ -59,12 +63,34 @@ public interface ICraftingCPU extends IBaseMonitor<IAEItemStack>
*/
String getName();

/**
* @return final output of the current crafting operation, or null if not crafting an item
* @deprecated implement and use {@link #getTargetOutput()} instead.
*/
@Deprecated
@Nullable
default IAEItemStack getFinalOutput()
{
final IExAEStack<?> out = this.getTargetOutput();
if ( out == null )
{
return null;
}

final IAEStack<?> outStack = out.unwrap();
if (outStack instanceof IAEItemStack)
{
return (IAEItemStack) outStack;
}

return AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createStack(outStack.asItemStackRepresentation());
}

/**
* @return final output of the current crafting operation, or null if not crafting
*/
@Nullable
default IAEItemStack getFinalOutput()
default IExAEStack<?> getTargetOutput()
{
return null;
}
Expand Down
92 changes: 85 additions & 7 deletions src/api/java/appeng/api/networking/crafting/ICraftingGrid.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.util.concurrent.Future;

import appeng.api.storage.data.IAEStack;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableSet;

Expand All @@ -47,8 +48,44 @@ public interface ICraftingGrid extends IGridCache
* @param details pattern details
*
* @return a collection of crafting patterns for the item in question.
* @deprecated use {@link #getUnivCraftingFor(IAEStack, ICraftingPatternDetails, int, World)} instead.
*/
ImmutableCollection<ICraftingPatternDetails> getCraftingFor( IAEItemStack whatToCraft, ICraftingPatternDetails details, int slot, World world );
@Deprecated
default ImmutableCollection<ICraftingPatternDetails> getCraftingFor( final IAEItemStack whatToCraft, final ICraftingPatternDetails details, final int slot, final World world )
{
return this.getUnivCraftingFor(whatToCraft, details, slot, world);
}

/**
* @param whatToCraft requested craft
* @param world crafting world
* @param slot slot index
* @param details pattern details
*
* @return a collection of crafting patterns for the item in question.
*/
<T extends IAEStack<T>> ImmutableCollection<ICraftingPatternDetails> getUnivCraftingFor( T whatToCraft, ICraftingPatternDetails details, int slot, World world );


/**
* Begin calculating a crafting job.
*
* @param world crafting world
* @param grid network
* @param actionSrc source
* @param craftWhat result
* @param callback callback
* -- optional
*
* @return a future which will at an undetermined point in the future get you the {@link ICraftingJob} do not wait
* on this, your be waiting forever.
* @deprecated use {@link #beginUnivCraftingJob(World, IGrid, IActionSource, IAEStack, ICraftingCallback)} instead.
*/
@Deprecated
default Future<ICraftingJob> beginCraftingJob( final World world, final IGrid grid, final IActionSource actionSrc, final IAEItemStack craftWhat, final ICraftingCallback callback )
{
return this.beginUnivCraftingJob(world, grid, actionSrc, craftWhat, callback);
}

/**
* Begin calculating a crafting job.
Expand All @@ -63,7 +100,7 @@ public interface ICraftingGrid extends IGridCache
* @return a future which will at an undetermined point in the future get you the {@link ICraftingJob} do not wait
* on this, your be waiting forever.
*/
Future<ICraftingJob> beginCraftingJob( World world, IGrid grid, IActionSource actionSrc, IAEItemStack craftWhat, ICraftingCallback callback );
<T extends IAEStack<T>> Future<ICraftingJob> beginUnivCraftingJob( World world, IGrid grid, IActionSource actionSrc, T craftWhat, ICraftingCallback callback );

/**
* Submit the job to the Crafting system for processing.
Expand All @@ -79,31 +116,72 @@ public interface ICraftingGrid extends IGridCache
*
* @return null ( if failed ) or an {@link ICraftingLink} other wise, if you send requestingMachine you need to
* properly keep track of this and handle the nbt saving and loading of the object as well as the
* {@link ICraftingRequester} methods. if you send null, this object should be discarded after verifying the
* {@link IUnivCraftingRequester} methods. if you send null, this object should be discarded after verifying the
* return state.
*/
ICraftingLink submitJob( ICraftingJob job, ICraftingRequester requestingMachine, ICraftingCPU target, boolean prioritizePower, IActionSource src );
ICraftingLink submitJob( ICraftingJob job, IUnivCraftingRequester requestingMachine, ICraftingCPU target, boolean prioritizePower, IActionSource src );

/**
* @return list of all the crafting cpus on the grid
*/
ImmutableSet<ICraftingCPU> getCpus();


/**
* @param what to be requested item
*
* @return true if the item can be requested via a crafting emitter.
* @deprecated use {@link #canEmitForUniv(IAEStack)} instead.
*/
@Deprecated
default boolean canEmitFor( final IAEItemStack what )
{
return this.canEmitForUniv(what);
}

/**
* @param what to be requested item
*
* @return true if the item can be requested via a crafting emitter.
*/
boolean canEmitFor( IAEItemStack what );
<T extends IAEStack<T>> boolean canEmitForUniv( T what );

/**
* is this item being crafted?
*
* @param what item being crafted
*
* @return true if it is being crafting
* @deprecated use {@link #isRequestingUniv(IAEStack)} instead.
*/
@Deprecated
default boolean isRequesting( final IAEItemStack what )
{
return this.isRequestingUniv(what);
}

/**
* is this item being crafted?
*
* @param what item being crafted
*
* @return true if it is being crafting
*/
<T extends IAEStack<T>> boolean isRequestingUniv( T what );

/**
* The total amount being requested across all crafting cpus of a grid.
*
* @param what item being requested, ignores stacksize
*
* @return The total amount being requested.
* @deprecated use {@link #requestingUniv(IAEStack)} instead.
*/
boolean isRequesting( IAEItemStack what );
@Deprecated
default long requesting( final IAEItemStack what )
{
return this.requestingUniv(what);
}

/**
* The total amount being requested across all crafting cpus of a grid.
Expand All @@ -112,5 +190,5 @@ public interface ICraftingGrid extends IGridCache
*
* @return The total amount being requested.
*/
long requesting( IAEItemStack what );
<T extends IAEStack<T>> long requestingUniv( T what );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package appeng.api.networking.crafting;

import appeng.api.storage.data.IAEStack;
import appeng.api.util.IExAEStack;
import appeng.api.util.IUnivStackIterable;
import net.minecraft.inventory.InventoryCrafting;

/**
* Represents a variant of {@link InventoryCrafting} with heterogeneous item slots for use as an autocrafting buffer.
*/
public interface ICraftingInventory extends IUnivStackIterable
{

/**
* @return the width of the crafting area
*/
int getWidth();

/**
* @return the height of the crafting area
*/
int getHeight();

/**
* @return the number of slots in the inventory
*/
int getSlotCount();

/**
* Sets the item stack in the given inventory slot.
*
* @param slotIndex the index of the slot
* @param stack the stack to insert
*/
<T extends IAEStack<T>> void setStackInSlot( int slotIndex, T stack );

/**
* Sets the item stack in the given inventory slot.
*
* @param slotIndex the index of the slot
* @param stack the stack to insert
*/
<T extends IAEStack<T>> void setStackInSlot( final int slotIndex, final IExAEStack<T> stack );

/**
* Retrieves the item stack in the given inventory slot.
*
* @param slotIndex the index of the slot
* @return the stack in the slot
*/
IExAEStack<?> getStackInSlot(int slotIndex );

/**
* Coerces the contents of this inventory into a vanilla {@link InventoryCrafting}.
*
* @return the vanilla crafting inventory, or null if this inventory contains non-item ingredients
*/
InventoryCrafting asVanilla();
}
Loading