Workbench - Client/server sync
Also fixed issue with display names
This commit is contained in:
parent
982dc9b25d
commit
1c8932193c
7 changed files with 80 additions and 7 deletions
|
@ -56,7 +56,7 @@ public class RShapedOreRecipeWrapper
|
|||
@Override
|
||||
public String getName( )
|
||||
{
|
||||
return this.recipe.getRecipeOutput( ).getUnlocalizedName( );
|
||||
return this.recipe.getRecipeOutput( ).getUnlocalizedName( ) + ".name";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public class RShapedRecipeWrapper
|
|||
@Override
|
||||
public String getName( )
|
||||
{
|
||||
return this.recipe.getRecipeOutput( ).getUnlocalizedName( );
|
||||
return this.recipe.getRecipeOutput( ).getUnlocalizedName( ) + ".name";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ public class RShapelessOreRecipeWrapper
|
|||
@Override
|
||||
public String getName( )
|
||||
{
|
||||
return this.recipe.getRecipeOutput( ).getUnlocalizedName( );
|
||||
return this.recipe.getRecipeOutput( ).getUnlocalizedName( ) + ".name";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ public class RShapelessRecipeWrapper
|
|||
@Override
|
||||
public String getName( )
|
||||
{
|
||||
return this.recipe.getRecipeOutput( ).getUnlocalizedName( );
|
||||
return this.recipe.getRecipeOutput( ).getUnlocalizedName( ) + ".name";
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import mmm.Mmm;
|
||||
import mmm.core.CNetwork;
|
||||
import mmm.core.api.recipes.I_CraftingRecipeWrapper;
|
||||
import mmm.recipes.RCraftingWrappers;
|
||||
import mmm.utils.gui.A_UGContainerScreen;
|
||||
|
@ -72,7 +73,7 @@ public class TBWBGui
|
|||
this.buttonList.add( this.bPrevious );
|
||||
this.buttonList.add( this.bNext );
|
||||
this.buttonList.add( this.bSetDefault );
|
||||
|
||||
|
||||
this.enableButtons( );
|
||||
}
|
||||
|
||||
|
@ -130,8 +131,9 @@ public class TBWBGui
|
|||
index = 0;
|
||||
}
|
||||
this.currentRecipe = index;
|
||||
this.container.setCurrentRecipe( index == -1 ? null : this.recipes.get( index ) , false );
|
||||
// CNetwork.sendToServer( new TBAFMessage( rName , false ) );
|
||||
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( );
|
||||
}
|
||||
|
||||
|
|
69
src/java/mmm/tech/base/workbench/TBWBMessage.java
Normal file
69
src/java/mmm/tech/base/workbench/TBWBMessage.java
Normal file
|
@ -0,0 +1,69 @@
|
|||
package mmm.tech.base.workbench;
|
||||
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import mmm.core.api.I_Message;
|
||||
import mmm.core.api.recipes.I_CraftingRecipeWrapper;
|
||||
import mmm.recipes.RCraftingWrappers;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
|
||||
|
||||
|
||||
public class TBWBMessage
|
||||
implements I_Message
|
||||
{
|
||||
private String name;
|
||||
private boolean setDefault;
|
||||
|
||||
|
||||
public TBWBMessage( )
|
||||
{
|
||||
// EMPTY
|
||||
}
|
||||
|
||||
|
||||
public TBWBMessage( final String name , final boolean setDefault )
|
||||
{
|
||||
this.name = name;
|
||||
this.setDefault = setDefault;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fromBytes( final ByteBuf buf )
|
||||
{
|
||||
if ( buf.readBoolean( ) ) {
|
||||
this.name = ByteBufUtils.readUTF8String( buf );
|
||||
} else {
|
||||
this.name = null;
|
||||
}
|
||||
this.setDefault = buf.readBoolean( );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void toBytes( final ByteBuf buf )
|
||||
{
|
||||
buf.writeBoolean( this.name != null );
|
||||
if ( this.name != null ) {
|
||||
ByteBufUtils.writeUTF8String( buf , this.name );
|
||||
}
|
||||
buf.writeBoolean( this.setDefault );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleOnServer( final EntityPlayerMP player )
|
||||
{
|
||||
final Container curCont = player.openContainer;
|
||||
if ( ! ( curCont instanceof TBWBContainer ) ) {
|
||||
return;
|
||||
}
|
||||
final TBWBContainer container = (TBWBContainer) curCont;
|
||||
final I_CraftingRecipeWrapper wrapper = RCraftingWrappers.IDENTIFIERS.get( this.name );
|
||||
container.setCurrentRecipe( wrapper , this.setDefault );
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@ package mmm.tech.base.workbench;
|
|||
|
||||
|
||||
import mmm.core.CGui;
|
||||
import mmm.core.CNetwork;
|
||||
import mmm.core.CRegistry;
|
||||
import mmm.core.api.I_RecipeRegistrar;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
|
@ -55,6 +56,7 @@ public class TBWorkbench
|
|||
CGui.registerTileEntityGUI( TBWBTileEntity.class , //
|
||||
"mmm.tech.base.workbench.TBWBContainer" , //
|
||||
"mmm.tech.base.workbench.TBWBGui" );
|
||||
CNetwork.addServerMessage( TBWBMessage.class );
|
||||
}
|
||||
|
||||
|
||||
|
|
Reference in a new issue