Workbench - Repair recipes
This commit is contained in:
parent
f93e75304b
commit
6165651b51
3 changed files with 156 additions and 0 deletions
|
@ -64,5 +64,6 @@ public class RCraftingWrappers
|
|||
RCraftingWrappers.register( new RShapedOreRecipeWrapperFactory( ) );
|
||||
RCraftingWrappers.register( new RMapCloningRecipeWrapperFactory( ) );
|
||||
RCraftingWrappers.register( new RMapExtendingRecipeWrapperFactory( ) );
|
||||
RCraftingWrappers.register( new RRepairRecipeWrapperFactory( ) );
|
||||
}
|
||||
}
|
||||
|
|
116
src/java/mmm/recipes/RRepairRecipeWrapper.java
Normal file
116
src/java/mmm/recipes/RRepairRecipeWrapper.java
Normal file
|
@ -0,0 +1,116 @@
|
|||
package mmm.recipes;
|
||||
|
||||
|
||||
import mmm.core.api.recipes.I_CraftingRecipeWrapper;
|
||||
import mmm.core.api.recipes.I_RecipeRequirements;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
|
||||
|
||||
public class RRepairRecipeWrapper
|
||||
implements I_CraftingRecipeWrapper
|
||||
{
|
||||
private class RepairRequirements
|
||||
extends RRequirements
|
||||
{
|
||||
|
||||
RepairRequirements( )
|
||||
{
|
||||
super( 2 );
|
||||
this.put( 0 , new ItemStack( RRepairRecipeWrapper.this.item ) , 2 );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean checkItemStack( final int pos , final ItemStack stack , final World world )
|
||||
{
|
||||
return stack != null && stack.getItem( ) == RRepairRecipeWrapper.this.item && stack.isItemDamaged( );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final Item item;
|
||||
private final RepairRequirements requirements;
|
||||
private final IRecipe originalRecipe;
|
||||
private static InventoryCrafting tempInventory = null;
|
||||
|
||||
|
||||
public RRepairRecipeWrapper( final IRecipe originalRecipe , final Item item )
|
||||
{
|
||||
this.item = item;
|
||||
this.requirements = new RepairRequirements( );
|
||||
this.originalRecipe = originalRecipe;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getIdentifier( )
|
||||
{
|
||||
return "REPAIR:" + this.item.getRegistryName( ).toString( );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName( )
|
||||
{
|
||||
return this.item.getUnlocalizedName( );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack getOutput( )
|
||||
{
|
||||
return new ItemStack( this.item );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemStack getActualOutput( final IInventory input )
|
||||
{
|
||||
if ( RRepairRecipeWrapper.tempInventory == null ) {
|
||||
RRepairRecipeWrapper.tempInventory = new InventoryCrafting( new Container( ) {
|
||||
|
||||
@Override
|
||||
public boolean canInteractWith( final EntityPlayer playerIn )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
} , 3 , 3 );
|
||||
}
|
||||
|
||||
RRepairRecipeWrapper.tempInventory.clear( );
|
||||
for ( int i = 0 , j = 0 ; i < input.getSizeInventory( ) && j != 2 ; i++ ) {
|
||||
final ItemStack stack = input.getStackInSlot( i );
|
||||
if ( this.requirements.checkItemStack( 0 , stack , null ) ) {
|
||||
RRepairRecipeWrapper.tempInventory.setInventorySlotContents( j++ , stack );
|
||||
}
|
||||
}
|
||||
return this.originalRecipe.getCraftingResult( RRepairRecipeWrapper.tempInventory );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addInputsToDisplay( final IInventory displayInventory )
|
||||
{
|
||||
final ItemStack stack = new ItemStack( this.item );
|
||||
stack.setItemDamage( this.item.getMaxDamage( ) - 1 );
|
||||
displayInventory.setInventorySlotContents( 0 , stack.copy( ) );
|
||||
displayInventory.setInventorySlotContents( 1 , stack );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public I_RecipeRequirements getRequirements( )
|
||||
{
|
||||
return this.requirements;
|
||||
}
|
||||
|
||||
}
|
39
src/java/mmm/recipes/RRepairRecipeWrapperFactory.java
Normal file
39
src/java/mmm/recipes/RRepairRecipeWrapperFactory.java
Normal file
|
@ -0,0 +1,39 @@
|
|||
package mmm.recipes;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mmm.core.api.recipes.I_CraftingRecipeWrapper;
|
||||
import mmm.core.api.recipes.I_CraftingRecipeWrapperFactory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.RecipeRepairItem;
|
||||
|
||||
|
||||
|
||||
public class RRepairRecipeWrapperFactory
|
||||
implements I_CraftingRecipeWrapperFactory
|
||||
{
|
||||
|
||||
@Override
|
||||
public Class< ? extends IRecipe > getRecipeClass( )
|
||||
{
|
||||
return RecipeRepairItem.class;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List< I_CraftingRecipeWrapper > createWrappers( final IRecipe recipe )
|
||||
{
|
||||
final ArrayList< I_CraftingRecipeWrapper > repairWrappers = new ArrayList<>( );
|
||||
for ( final Item item : Item.REGISTRY ) {
|
||||
if ( item.isItemTool( new ItemStack( item ) ) && item.isRepairable( ) ) {
|
||||
repairWrappers.add( new RRepairRecipeWrapper( recipe , item ) );
|
||||
}
|
||||
}
|
||||
return repairWrappers;
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue