22
33import com .dani .blacksmithmod .BlacksmithMod ;
44import com .dani .blacksmithmod .items .Hammer ;
5- import com .dani .blacksmithmod .tiles .anviltileentity .AnvilTileEntity ;
5+ import com .dani .blacksmithmod .setup .TileEntityRegister ;
6+ import com .dani .blacksmithmod .tiles .AnvilTileEntity ;
67import net .minecraft .block .*;
78import net .minecraft .block .material .Material ;
89import net .minecraft .entity .player .PlayerEntity ;
910import net .minecraft .entity .player .ServerPlayerEntity ;
1011import net .minecraft .inventory .container .INamedContainerProvider ;
11- import net .minecraft .state .DirectionProperty ;
1212import net .minecraft .tileentity .TileEntity ;
1313import net .minecraft .util .*;
1414import net .minecraft .util .math .BlockPos ;
1515import net .minecraft .util .math .BlockRayTraceResult ;
1616import net .minecraft .util .math .shapes .ISelectionContext ;
1717import net .minecraft .util .math .shapes .VoxelShape ;
1818import net .minecraft .util .math .shapes .VoxelShapes ;
19- import net .minecraft .util .text .TranslationTextComponent ;
2019import net .minecraft .world .IBlockReader ;
2120import net .minecraft .world .World ;
2221import net .minecraftforge .common .ToolType ;
2322import net .minecraftforge .fml .network .NetworkHooks ;
2423
2524import javax .annotation .Nullable ;
2625
26+
27+ /**
28+ * Anvil block, this blocks is used to craft items from blacksmith mod and minecraft vanilla
29+ */
2730public class Anvil extends Block {
2831
32+ //VoxelShape for the anvil block.
2933 private static final VoxelShape PART_BASE = Block .makeCuboidShape (1.0D , 0.0D , 1.0D , 15.0D , 4.0D , 15.0D );
3034 private static final VoxelShape PART_LOWER_X = Block .makeCuboidShape (3.0D , 4.0D , 3.0D , 13.0D , 5.0D , 13.0D );
3135 private static final VoxelShape PART_MID_X = Block .makeCuboidShape (4.0D , 5.0D , 4.0D , 12.0D , 10.0D , 12.0D );
3236 private static final VoxelShape PART_UPPER_X = Block .makeCuboidShape (1.0D , 10.0D , 1.0D , 15.0D , 15.0D , 15.0D );
33-
3437 private static final VoxelShape X_AXIS_AABB = VoxelShapes .or (PART_BASE , PART_LOWER_X , PART_MID_X , PART_UPPER_X );
3538
3639
@@ -41,67 +44,83 @@ public Anvil() {
4144 .harvestLevel (1 )
4245 .harvestTool (ToolType .PICKAXE ));
4346 this .setRegistryName (BlacksmithMod .MODID ,"anvil" );
44-
4547 }
4648
4749 /**
48- * Verifica si este blqoue tiene un TileEntity
49- * @param state Estado del bloque
50- * @return Retorna TRUE, porque posee un tileEntity
50+ * Verify if this block has TileEntity
51+ * @param state Block state
52+ * @return True, it has TileEntity
5153 */
5254 @ Override
5355 public boolean hasTileEntity (BlockState state ) {
5456 return true ;
5557 }
5658
5759 /**
58- * Este metodo crea el tileEntity al bloque
59- * @param state Estado del bloque
60- * @param world Mundo donde esta el bloque
61- * @return retorna un AnvilTileEntity
60+ * This method make a TileEntity to Anvil Block
61+ * @param state Block state
62+ * @param world World where it's.
63+ * @return new AnvilTileEntity object.
6264 */
6365 @ Nullable
6466 @ Override
6567 public TileEntity createTileEntity (BlockState state , IBlockReader world ) {
66- return new AnvilTileEntity ();
68+ return TileEntityRegister . ANVIL_TILE_ENTITY . create ();
6769 }
6870
71+ /**
72+ * Create a custom VoxelShape
73+ * @param state Block state
74+ * @param worldIn World Render
75+ * @param pos Block position
76+ * @param context Context
77+ * @return Custom VoxelShape
78+ */
6979 @ Override
7080 public VoxelShape getShape (BlockState state , IBlockReader worldIn , BlockPos pos , ISelectionContext context ) {
71-
7281 return X_AXIS_AABB ;
7382 }
7483
84+ /**
85+ * When the player use right click in it
86+ * @param state Block State
87+ * @param worldIn World where player and block stay
88+ * @param pos Block position
89+ * @param player Player who interact
90+ * @param handIn what had use
91+ * @param hit where the player hit the block
92+ * @return interaction result
93+ */
7594 @ Override
7695 public ActionResultType onBlockActivated (BlockState state , World worldIn , BlockPos pos , PlayerEntity player , Hand handIn , BlockRayTraceResult hit ){
77- if (worldIn .isRemote )
78- return ActionResultType .PASS ;
79-
80- TileEntity tileEntity = worldIn .getTileEntity (pos );
81- if (tileEntity instanceof INamedContainerProvider ) {
82- NetworkHooks .openGui ((ServerPlayerEntity ) player , (INamedContainerProvider ) tileEntity , tileEntity .getPos ());
96+ if (!worldIn .isRemote ()){ //when is True is Client side, and if is false es serve side
97+ TileEntity tileEntity = worldIn .getTileEntity (pos );
98+ if ( tileEntity instanceof INamedContainerProvider )
99+ NetworkHooks .openGui ((ServerPlayerEntity ) player , (INamedContainerProvider ) tileEntity , tileEntity .getPos ());
100+ return ActionResultType .SUCCESS ;
83101 }
84- return ActionResultType .SUCCESS ;
102+ return ActionResultType .PASS ;
85103 }
86104
87- // Cuando es True isremote() es el Cliente y si es False es El servidor
105+ /**
106+ * When the player use left click in it
107+ * @param state Block State
108+ * @param worldIn World where player and block stay
109+ * @param pos lock position
110+ * @param player Player who interact
111+ */
88112 @ Override
89113 public void onBlockClicked (BlockState state , World worldIn , BlockPos pos , PlayerEntity player ) {
90- if (! worldIn . isRemote () ){
91- if (player . inventory . getCurrentItem (). getItem () instanceof Hammer ){
114+ if ( player . inventory . getCurrentItem (). getItem () instanceof Hammer ){
115+ if (! worldIn . isRemote ()){ //server Side
92116 player .inventory .getCurrentItem ().getItem ().setDamage (player .inventory .getCurrentItem (),1 );
93117 TileEntity tileEntity = worldIn .getTileEntity (pos );
94- if (tileEntity instanceof AnvilTileEntity ){
95-
118+ if (tileEntity instanceof AnvilTileEntity )
96119 ((AnvilTileEntity ) tileEntity ).addHit ();
97- }
98- }
99- }
100120
101- if ( player . inventory . getCurrentItem (). getItem () instanceof Hammer && worldIn . isRemote ()){
102- worldIn .playSound (player .getPosX (),player .getPosY (),player .getPosZ (),SoundType .ANVIL .getPlaceSound (), SoundCategory .BLOCKS ,1.0f ,1.0f ,true );
121+ } else //client side
122+ worldIn .playSound (player .getPosX (),player .getPosY (),player .getPosZ (),SoundType .ANVIL .getPlaceSound (), SoundCategory .BLOCKS ,1.0f ,1.0f ,true );
103123 }
104-
105-
106124 }
125+
107126}
0 commit comments