diff --git a/alloy-furnace-gui-1.xcf b/alloy-furnace-gui-1.xcf index d6135f5..04a7276 100644 Binary files a/alloy-furnace-gui-1.xcf and b/alloy-furnace-gui-1.xcf differ diff --git a/src/java/mmm/tech/base/TBAlloyFurnaceContainer.java b/src/java/mmm/tech/base/TBAlloyFurnaceContainer.java index d9d05b8..afb7df7 100644 --- a/src/java/mmm/tech/base/TBAlloyFurnaceContainer.java +++ b/src/java/mmm/tech/base/TBAlloyFurnaceContainer.java @@ -5,7 +5,6 @@ import mmm.materials.MAlloyRecipe; import mmm.utils.UContainers; import mmm.utils.UInventoryDisplay; import mmm.utils.UInventoryGrid; -import mmm.utils.URegistry; import mmm.utils.slots.USDisplay; import mmm.utils.slots.USFuel; import mmm.utils.slots.USOutput; @@ -84,9 +83,8 @@ public class TBAlloyFurnaceContainer public void setCurrentRecipe( final ResourceLocation name , final boolean confirm ) { - MAlloyRecipe recipe = MAlloyRecipe.REGISTRY.getRecipe( name ); + final MAlloyRecipe recipe = MAlloyRecipe.REGISTRY.getRecipe( name ); if ( recipe == null ) { - // XXX log return; } @@ -97,8 +95,7 @@ public class TBAlloyFurnaceContainer this.recipe.setInventorySlotContents( 6 , recipe.output ); if ( confirm ) { - this.tileEntity.recipe = recipe; - URegistry.network.sendToAll( new TBAlloyFurnaceMessage( this.position , name , true ) ); + this.tileEntity.setRecipe( name ); } } diff --git a/src/java/mmm/tech/base/TBAlloyFurnaceMessage.java b/src/java/mmm/tech/base/TBAlloyFurnaceMessage.java index 7652d40..1dbd387 100644 --- a/src/java/mmm/tech/base/TBAlloyFurnaceMessage.java +++ b/src/java/mmm/tech/base/TBAlloyFurnaceMessage.java @@ -2,18 +2,12 @@ package mmm.tech.base; import io.netty.buffer.ByteBuf; -import mmm.materials.MAlloyRecipe; import mmm.utils.I_UMessage; -import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; import net.minecraftforge.fml.common.network.ByteBufUtils; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; @@ -60,36 +54,14 @@ public class TBAlloyFurnaceMessage } - @Override - @SideOnly( Side.CLIENT ) - public void handleOnClient( final EntityPlayerSP player ) - { - World world = player.getEntityWorld( ); - TileEntity te = world.getTileEntity( this.blockPos ); - if ( ! ( te instanceof TBAlloyFurnaceTileEntity ) ) { - return; - } - - TBAlloyFurnaceTileEntity afte = (TBAlloyFurnaceTileEntity) te; - MAlloyRecipe recipe = MAlloyRecipe.REGISTRY.getRecipe( selected ); - if ( recipe == null ) { - recipe = MAlloyRecipe.REGISTRY.getRecipes( ).get( 0 ); - } - afte.recipe = recipe; - } - - @Override public void handleOnServer( final EntityPlayerMP player ) { final Container curCont = player.openContainer; - if ( ! ( curCont instanceof TBAlloyFurnaceContainer ) ) { - // XXX log? - return; + if ( curCont instanceof TBAlloyFurnaceContainer ) { + final TBAlloyFurnaceContainer container = (TBAlloyFurnaceContainer) curCont; + container.setCurrentRecipe( this.selected , this.confirm ); } - - final TBAlloyFurnaceContainer container = (TBAlloyFurnaceContainer) curCont; - container.setCurrentRecipe( this.selected , this.confirm ); } } diff --git a/src/java/mmm/tech/base/TBAlloyFurnaceTileEntity.java b/src/java/mmm/tech/base/TBAlloyFurnaceTileEntity.java index 9cd0a86..9a8fa56 100644 --- a/src/java/mmm/tech/base/TBAlloyFurnaceTileEntity.java +++ b/src/java/mmm/tech/base/TBAlloyFurnaceTileEntity.java @@ -3,7 +3,10 @@ package mmm.tech.base; import mmm.materials.MAlloyRecipe; import mmm.utils.UInventoryGrid; +import net.minecraft.block.state.IBlockState; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.util.Constants.NBT; @@ -17,6 +20,7 @@ public class TBAlloyFurnaceTileEntity public final UInventoryGrid input; public final UInventoryGrid fuel; public final UInventoryGrid output; + public MAlloyRecipe recipe; @@ -36,11 +40,7 @@ public class TBAlloyFurnaceTileEntity this.input.deserializeNBT( compound.getTagList( "Input" , NBT.TAG_COMPOUND ) ); this.fuel.deserializeNBT( compound.getTagList( "Fuel" , NBT.TAG_COMPOUND ) ); this.output.deserializeNBT( compound.getTagList( "Output" , NBT.TAG_COMPOUND ) ); - String recipeName = compound.getString( "Recipe" ); - this.recipe = MAlloyRecipe.REGISTRY.getRecipe( new ResourceLocation( recipeName ) ); - if ( this.recipe == null ) { - this.recipe = MAlloyRecipe.REGISTRY.getRecipes( ).get( 0 ); - } + this.readSyncData( compound ); } @@ -51,8 +51,74 @@ public class TBAlloyFurnaceTileEntity compound.setTag( "Input" , this.input.serializeNBT( ) ); compound.setTag( "Fuel" , this.fuel.serializeNBT( ) ); compound.setTag( "Output" , this.output.serializeNBT( ) ); - compound.setString( "Recipe" , this.recipe.name.toString( ) ); + this.writeSyncData( compound ); + System.err.println( "tag " + compound.toString( ) ); return compound; } + + @Override + public SPacketUpdateTileEntity getUpdatePacket( ) + { + final NBTTagCompound compound = new NBTTagCompound( ); + this.writeSyncData( compound ); + return new SPacketUpdateTileEntity( this.pos , 0 , compound ); + } + + + @Override + public NBTTagCompound getUpdateTag( ) + { + final NBTTagCompound compound = new NBTTagCompound( ); + this.writeToNBT( compound ); + return compound; + } + + + @Override + public void onDataPacket( final NetworkManager net , final SPacketUpdateTileEntity pkt ) + { + if ( this.worldObj.isRemote ) { + this.readSyncData( pkt.getNbtCompound( ) ); + final IBlockState state = this.worldObj.getBlockState( this.pos ); + this.worldObj.notifyBlockUpdate( this.pos , state , state , 3 ); + } + } + + + public void setRecipe( final ResourceLocation location ) + { + MAlloyRecipe recipe = MAlloyRecipe.REGISTRY.getRecipe( location ); + if ( recipe == null ) { + recipe = MAlloyRecipe.REGISTRY.getRecipes( ).get( 0 ); + } + + if ( recipe == this.recipe ) { + return; + } + this.recipe = recipe; + + if ( !this.worldObj.isRemote ) { + this.markDirty( ); + final IBlockState state = this.worldObj.getBlockState( this.pos ); + this.worldObj.notifyBlockUpdate( this.pos , state , state , 3 ); + } + } + + + private void readSyncData( final NBTTagCompound compound ) + { + final String recipeName = compound.getString( "Recipe" ); + this.recipe = MAlloyRecipe.REGISTRY.getRecipe( new ResourceLocation( recipeName ) ); + if ( this.recipe == null ) { + this.recipe = MAlloyRecipe.REGISTRY.getRecipes( ).get( 0 ); + } + } + + + private void writeSyncData( final NBTTagCompound compound ) + { + compound.setString( "Recipe" , this.recipe.name.toString( ) ); + } + } diff --git a/src/java/mmm/tech/base/TechBase.java b/src/java/mmm/tech/base/TechBase.java index 62ed93d..87c73d9 100644 --- a/src/java/mmm/tech/base/TechBase.java +++ b/src/java/mmm/tech/base/TechBase.java @@ -30,7 +30,6 @@ public class TechBase GameRegistry.registerTileEntity( TBAlloyFurnaceTileEntity.class , "mmm:tech/base/alloy_furnace" ); NetworkRegistry.INSTANCE.registerGuiHandler( Mmm.get( ) , new TBAlloyFurnaceGuiHandler( ) ); URegistry.addServerMessage( TBAlloyFurnaceMessage.class ); - URegistry.addClientMessage( TBAlloyFurnaceMessage.class ); // FIXME test, remove this later MAlloyRecipe.build( ).setName( "test" ).setBurnTime( 200 ).setExperience( .05f ) diff --git a/src/resources/assets/mmm/textures/gui/alloy_furnace_1.png b/src/resources/assets/mmm/textures/gui/alloy_furnace_1.png index 36cbaad..2fded74 100644 Binary files a/src/resources/assets/mmm/textures/gui/alloy_furnace_1.png and b/src/resources/assets/mmm/textures/gui/alloy_furnace_1.png differ