From b68a081350499eb42a78938c409fa6bbb81af275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Wed, 22 Jun 2016 15:34:20 +0200 Subject: [PATCH] Alloy furnace - More reliance on vanilla TE updates --- alloy-furnace-gui-1.xcf | Bin 43441 -> 43441 bytes .../tech/base/TBAlloyFurnaceContainer.java | 7 +- .../mmm/tech/base/TBAlloyFurnaceMessage.java | 34 +------- .../tech/base/TBAlloyFurnaceTileEntity.java | 78 ++++++++++++++++-- src/java/mmm/tech/base/TechBase.java | 1 - .../mmm/textures/gui/alloy_furnace_1.png | Bin 2169 -> 2172 bytes 6 files changed, 77 insertions(+), 43 deletions(-) diff --git a/alloy-furnace-gui-1.xcf b/alloy-furnace-gui-1.xcf index d6135f55b7a310e0bc567b468feccc447445241e..04a727648244b8c28d90dc93a4292a2a5bc33d31 100644 GIT binary patch delta 89 zcmdmZnQ7x?rU`b8K^yJe85vVHw=@1@nq1FOF!?QuhN=<+1PA~r5N2UuU^PP(V|CkX a#rl+qndLv%WF?N+$xk_RHh<>Ww*UaxEfq-s delta 101 zcmdmZnQ7x?rU`b8b{p;885v_Xw=@1@n*5YAWAaxP4NWNq2oL~LAk4zRz^aET#%c%R kPqtx`+MK|8oQawFKlfxUj@ZeqECrJvh_Y<{%&~6)0J_~5ssI20 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 36cbaad31063b97d94930d2e8e2de8c1235ce700..2fded745ce4f251adcbc7f64d0a3466b4cf504b1 100644 GIT binary patch delta 1921 zcmZuuX;{+v7XE=KI9^I8*9ap_GzghL&2HODN`KiH%0;xG#UnOBfVdq%}4! zrK63RX63%1%}`p6;x%=0O>ERuL?#nZmdiZzWj@^V?VR(R_q>bDKyHw~9XdoL91KVq z6;8N+XC7^ZT$zfI!#yVPjjqO|(E5T$n4w)2sF;W#SX+x=OCvhvZca?IPQ}%O$C{g) z&u=cw>ERt@(vKz5y$p`j^9);FNwnCRu#j18BHOv}9I?E9wtr4Ti)57N{LOmiT&h*H z)xX6=Bmd34dhX=L_h+Nbp|mV|a%ADTh0>yS3MaC(#@lZ2k z<;wv-%d{bq%v>vn7GzQ|y!iQB2y$OnWEHx=*hgXiN3A^t4qVytXTl(orv?N?@6Od8tja!EVI~%z#Eb>DBmGyLoma)B(uHD(lqoVNTZ;Dp#>e7lA z+otJEmEuPMWIbe|g#u#aEP3Hjj0%Z6tiF_5X^KJY~b_zVf;JK^P1BdA-M}}OTYXVKbX~Fxe;;P z)x_;B74rL1;R0ZIVMpj=N)-K)Z&k|{;YfDg{oBSi+?Dyz~`_&E-lr_IOK8+lptDU#ado@J|~{; z7Gak4M0+z-kexs|hgPi>k#~Z%wKc)~{DYO8z(>WEjFCi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