Workbench - Default recipe
This commit is contained in:
parent
f121e8bd3d
commit
7a964b4e09
3 changed files with 70 additions and 32 deletions
|
@ -55,7 +55,10 @@ public class TBWBContainer
|
|||
|
||||
this.slotGroups.endGroups( );
|
||||
|
||||
this.recipeWrapper = RCraftingWrappers.IDENTIFIERS.get( tileEntity.getDefaultRecipe( ) );
|
||||
if ( this.recipeWrapper == null ) {
|
||||
this.recipeWrapper = RCraftingWrappers.RECIPES.get( 0 );
|
||||
}
|
||||
this.onRecipeChanged( );
|
||||
}
|
||||
|
||||
|
@ -69,24 +72,25 @@ public class TBWBContainer
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ItemStack transferStackInSlot( EntityPlayer playerIn , int index )
|
||||
public ItemStack transferStackInSlot( final EntityPlayer playerIn , final int index )
|
||||
{
|
||||
Slot slot = (Slot) this.inventorySlots.get( index );
|
||||
final Slot slot = this.inventorySlots.get( index );
|
||||
if ( slot == null || !slot.getHasStack( ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ItemStack slotStack = slot.getStack( );
|
||||
ItemStack outStack = slotStack.copy( );
|
||||
final ItemStack slotStack = slot.getStack( );
|
||||
final ItemStack outStack = slotStack.copy( );
|
||||
|
||||
int group = this.slotGroups.getGroup( index );
|
||||
final int group = this.slotGroups.getGroup( index );
|
||||
if ( group == 3 ) {
|
||||
// Craft as many as possible
|
||||
if ( this.recipeWrapper == null ) {
|
||||
return null;
|
||||
}
|
||||
IInventory storage = this.getStorage( );
|
||||
final IInventory storage = this.getStorage( );
|
||||
if ( storage == null ) {
|
||||
return null;
|
||||
}
|
||||
|
@ -140,7 +144,8 @@ public class TBWBContainer
|
|||
}
|
||||
|
||||
|
||||
public boolean canMergeSlot( ItemStack stack , Slot slotIn )
|
||||
@Override
|
||||
public boolean canMergeSlot( final ItemStack stack , final Slot slotIn )
|
||||
{
|
||||
return slotIn.inventory != this.recipeOutput && super.canMergeSlot( stack , slotIn );
|
||||
}
|
||||
|
@ -149,11 +154,12 @@ public class TBWBContainer
|
|||
public void setCurrentRecipe( final I_CraftingRecipeWrapper wrapper , final boolean setDefault )
|
||||
{
|
||||
this.recipeWrapper = wrapper;
|
||||
|
||||
onRecipeChanged( );
|
||||
|
||||
this.onRecipeChanged( );
|
||||
if ( setDefault ) {
|
||||
// this.tileEntity.setDefaultRecipe( wrapper.getIdentifier( ) );
|
||||
final TileEntity te = this.world.getTileEntity( this.position );
|
||||
if ( te instanceof TBWBTileEntity ) {
|
||||
( (TBWBTileEntity) te ).setDefaultRecipe( wrapper == null ? "" : wrapper.getIdentifier( ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,7 +178,7 @@ public class TBWBContainer
|
|||
|
||||
public IInventory getStorage( )
|
||||
{
|
||||
TileEntity te = this.world.getTileEntity( position );
|
||||
final TileEntity te = this.world.getTileEntity( this.position );
|
||||
if ( te instanceof TBWBTileEntity ) {
|
||||
return ( (TBWBTileEntity) te ).storage;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,11 @@ public class TBWBGui
|
|||
|
||||
this.searchString = "";
|
||||
this.recipes = RCraftingWrappers.RECIPES;
|
||||
this.setRecipe( -1 );
|
||||
int index = this.recipes.indexOf( this.container.getCurrentRecipe( ) );
|
||||
if ( index == -1 && !this.recipes.isEmpty( ) ) {
|
||||
index = 0;
|
||||
}
|
||||
this.setRecipe( index );
|
||||
}
|
||||
|
||||
|
||||
|
@ -95,8 +99,8 @@ public class TBWBGui
|
|||
if ( this.currentRecipe == -1 ) {
|
||||
canCraft = false;
|
||||
} else {
|
||||
TileEntity te = this.container.world.getTileEntity( this.container.position );
|
||||
I_RecipeRequirements requirements = this.recipes.get( this.currentRecipe ).getRequirements( );
|
||||
final TileEntity te = this.container.world.getTileEntity( this.container.position );
|
||||
final I_RecipeRequirements requirements = this.recipes.get( this.currentRecipe ).getRequirements( );
|
||||
canCraft = te instanceof TBWBTileEntity && requirements.checkInventory( ( (TBWBTileEntity) te ).storage );
|
||||
}
|
||||
if ( !canCraft ) {
|
||||
|
@ -137,6 +141,13 @@ public class TBWBGui
|
|||
this.setRecipe( this.currentRecipe + 1 );
|
||||
} else if ( button == this.bPrevious && this.currentRecipe > 0 ) {
|
||||
this.setRecipe( this.currentRecipe - 1 );
|
||||
} else if ( button == this.bSetDefault ) {
|
||||
final I_CraftingRecipeWrapper wrapper = this.currentRecipe == -1
|
||||
? null
|
||||
: this.recipes.get( this.currentRecipe );
|
||||
this.container.setCurrentRecipe( wrapper , true );
|
||||
CNetwork.sendToServer( new TBWBMessage( wrapper == null ? null : wrapper.getIdentifier( ) , true ) );
|
||||
this.enableButtons( );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,7 +158,7 @@ public class TBWBGui
|
|||
index = 0;
|
||||
}
|
||||
this.currentRecipe = index;
|
||||
I_CraftingRecipeWrapper wrapper = index == -1 ? null : this.recipes.get( index );
|
||||
final I_CraftingRecipeWrapper wrapper = index == -1 ? null : this.recipes.get( index );
|
||||
this.container.setCurrentRecipe( wrapper , false );
|
||||
CNetwork.sendToServer( new TBWBMessage( wrapper == null ? null : wrapper.getIdentifier( ) , false ) );
|
||||
this.enableButtons( );
|
||||
|
@ -156,9 +167,22 @@ public class TBWBGui
|
|||
|
||||
private void enableButtons( )
|
||||
{
|
||||
if ( this.bNext != null ) {
|
||||
if ( this.bNext == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.bNext.enabled = !this.recipes.isEmpty( ) && this.currentRecipe < this.recipes.size( ) - 1;
|
||||
this.bPrevious.enabled = !this.recipes.isEmpty( ) && this.currentRecipe > 0;
|
||||
this.bSetDefault.enabled = false;
|
||||
if ( this.currentRecipe == -1 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
final TileEntity te = this.container.world.getTileEntity( this.container.position );
|
||||
if ( te instanceof TBWBTileEntity ) {
|
||||
final I_CraftingRecipeWrapper recipe = RCraftingWrappers.IDENTIFIERS
|
||||
.get( ( (TBWBTileEntity) te ).getDefaultRecipe( ) );
|
||||
this.bSetDefault.enabled = recipe != this.recipes.get( this.currentRecipe );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,7 +227,7 @@ public class TBWBGui
|
|||
}
|
||||
|
||||
|
||||
private int getRecipeIndex( I_CraftingRecipeWrapper selected )
|
||||
private int getRecipeIndex( final I_CraftingRecipeWrapper selected )
|
||||
{
|
||||
return this.recipes.indexOf( selected );
|
||||
}
|
||||
|
|
|
@ -37,15 +37,9 @@ public class TBWBTileEntity
|
|||
|
||||
}
|
||||
|
||||
public final UInventoryGrid storage;
|
||||
private String customName;
|
||||
|
||||
|
||||
public TBWBTileEntity( )
|
||||
{
|
||||
super( );
|
||||
this.storage = new Inventory( "Storage" , 3 , 5 );
|
||||
}
|
||||
public final UInventoryGrid storage = new Inventory( "Storage" , 3 , 5 );
|
||||
private String customName = "";
|
||||
private String defaultRecipe = "";
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -119,7 +113,7 @@ public class TBWBTileEntity
|
|||
|
||||
private void readSyncData( final NBTTagCompound compound )
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
this.defaultRecipe = compound.getString( "DefaultRecipe" );
|
||||
}
|
||||
|
||||
|
||||
|
@ -138,6 +132,20 @@ public class TBWBTileEntity
|
|||
|
||||
private void writeSyncData( final NBTTagCompound compound )
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
compound.setString( "DefaultRecipe" , this.defaultRecipe );
|
||||
}
|
||||
|
||||
|
||||
public String getDefaultRecipe( )
|
||||
{
|
||||
return this.defaultRecipe;
|
||||
}
|
||||
|
||||
|
||||
public void setDefaultRecipe( final String defaultRecipe )
|
||||
{
|
||||
this.defaultRecipe = defaultRecipe;
|
||||
this.markDirty( );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue