Workbench - Client/server sync

Also fixed issue with display names
This commit is contained in:
Emmanuel BENOîT 2016-07-16 16:30:04 +02:00
parent 982dc9b25d
commit 1c8932193c
7 changed files with 80 additions and 7 deletions

View file

@ -56,7 +56,7 @@ public class RShapedOreRecipeWrapper
@Override
public String getName( )
{
return this.recipe.getRecipeOutput( ).getUnlocalizedName( );
return this.recipe.getRecipeOutput( ).getUnlocalizedName( ) + ".name";
}

View file

@ -40,7 +40,7 @@ public class RShapedRecipeWrapper
@Override
public String getName( )
{
return this.recipe.getRecipeOutput( ).getUnlocalizedName( );
return this.recipe.getRecipeOutput( ).getUnlocalizedName( ) + ".name";
}

View file

@ -78,7 +78,7 @@ public class RShapelessOreRecipeWrapper
@Override
public String getName( )
{
return this.recipe.getRecipeOutput( ).getUnlocalizedName( );
return this.recipe.getRecipeOutput( ).getUnlocalizedName( ) + ".name";
}

View file

@ -56,7 +56,7 @@ public class RShapelessRecipeWrapper
@Override
public String getName( )
{
return this.recipe.getRecipeOutput( ).getUnlocalizedName( );
return this.recipe.getRecipeOutput( ).getUnlocalizedName( ) + ".name";
}

View file

@ -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;
@ -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( );
}

View 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 );
}
}

View file

@ -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 );
}