-
Notifications
You must be signed in to change notification settings - Fork 696
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,289 additions
and
52 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/main/java/appeng/api/integrations/emi/EmiStackConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package appeng.api.integrations.emi; | ||
|
||
import appeng.api.stacks.GenericStack; | ||
import dev.emi.emi.api.stack.EmiStack; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Implement this interface to provide AE2s EMI integration with a new way to convert between AE2 {@link GenericStack} | ||
* and {@link dev.emi.emi.api.stack.EmiStack}. | ||
* <ul> | ||
* <li>Recipe transfers</li> | ||
* <li>Pressing R/U on custom stacks in AE2 user interfaces</li> | ||
* <li>Dragging ghost items of custom types from EMI to AE2 interfaces</li> | ||
* </ul> | ||
* <p/> | ||
* To register your converter, see {@link EmiStackConverters}. | ||
*/ | ||
public interface EmiStackConverter { | ||
/** | ||
* The EMI {@link EmiStack#getKeyOfType key type} handled by this converter. | ||
* AE2 handles {@link net.minecraft.world.level.material.Fluid} and {@link net.minecraft.world.item.Item} already. | ||
*/ | ||
Class<?> getKeyType(); | ||
|
||
/** | ||
* Converts a generic stack into an EmiStack subtype handled by this converter. | ||
* <p/> | ||
* The converter needs to ensure the minimum amount of the returned ingredient is 1 if the resulting ingredient | ||
* represents amounts of 0 as "empty", since this would not preserve the ingredient type correctly. | ||
* <p/> | ||
* Example: <code>Math.max(1, Ints.saturatedCast(stack.amount()))</code> (for Item and Fluid stacks). | ||
* | ||
* @return Null if the converter can't handle the stack. | ||
*/ | ||
@Nullable | ||
EmiStack getIngredientFromStack(GenericStack stack); | ||
|
||
/** | ||
* Converts an EmiStack handled by this converter into a generic stack. | ||
* | ||
* @return Null if the ingredient represents an "empty" ingredient (i.e. | ||
* {@link EmiStack#EMPTY}. | ||
*/ | ||
@Nullable | ||
GenericStack getStackFromIngredient(EmiStack stack); | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/appeng/api/integrations/emi/EmiStackConverters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package appeng.api.integrations.emi; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Register your {@link EmiStackConverter} instances for JEI here. | ||
*/ | ||
public final class EmiStackConverters { | ||
private static List<EmiStackConverter> converters = ImmutableList.of(); | ||
|
||
private EmiStackConverters() { | ||
} | ||
|
||
/** | ||
* Registers a new EMI stack-converter for handling custom {@link appeng.api.stacks.AEKey key types} in the AE2 EMI | ||
* addon. | ||
* | ||
* @return false if a converter for the converters type has already been registered. | ||
*/ | ||
public static synchronized boolean register(EmiStackConverter converter) { | ||
for (var existingConverter : converters) { | ||
if (existingConverter.getKeyType() == converter.getKeyType()) { | ||
return false; | ||
} | ||
} | ||
converters = ImmutableList.<EmiStackConverter>builder() | ||
.addAll(converters) | ||
.add(converter) | ||
.build(); | ||
return true; | ||
} | ||
|
||
/** | ||
* @return The currently registered converters. | ||
*/ | ||
public static synchronized List<EmiStackConverter> getConverters() { | ||
return converters; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.