2
2
3
3
import com .dani .blacksmithmod .BlacksmithMod ;
4
4
import 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 ;
6
7
import net .minecraft .block .*;
7
8
import net .minecraft .block .material .Material ;
8
9
import net .minecraft .entity .player .PlayerEntity ;
9
10
import net .minecraft .entity .player .ServerPlayerEntity ;
10
11
import net .minecraft .inventory .container .INamedContainerProvider ;
11
- import net .minecraft .state .DirectionProperty ;
12
12
import net .minecraft .tileentity .TileEntity ;
13
13
import net .minecraft .util .*;
14
14
import net .minecraft .util .math .BlockPos ;
15
15
import net .minecraft .util .math .BlockRayTraceResult ;
16
16
import net .minecraft .util .math .shapes .ISelectionContext ;
17
17
import net .minecraft .util .math .shapes .VoxelShape ;
18
18
import net .minecraft .util .math .shapes .VoxelShapes ;
19
- import net .minecraft .util .text .TranslationTextComponent ;
20
19
import net .minecraft .world .IBlockReader ;
21
20
import net .minecraft .world .World ;
22
21
import net .minecraftforge .common .ToolType ;
23
22
import net .minecraftforge .fml .network .NetworkHooks ;
24
23
25
24
import javax .annotation .Nullable ;
26
25
26
+
27
+ /**
28
+ * Anvil block, this blocks is used to craft items from blacksmith mod and minecraft vanilla
29
+ */
27
30
public class Anvil extends Block {
28
31
32
+ //VoxelShape for the anvil block.
29
33
private static final VoxelShape PART_BASE = Block .makeCuboidShape (1.0D , 0.0D , 1.0D , 15.0D , 4.0D , 15.0D );
30
34
private static final VoxelShape PART_LOWER_X = Block .makeCuboidShape (3.0D , 4.0D , 3.0D , 13.0D , 5.0D , 13.0D );
31
35
private static final VoxelShape PART_MID_X = Block .makeCuboidShape (4.0D , 5.0D , 4.0D , 12.0D , 10.0D , 12.0D );
32
36
private static final VoxelShape PART_UPPER_X = Block .makeCuboidShape (1.0D , 10.0D , 1.0D , 15.0D , 15.0D , 15.0D );
33
-
34
37
private static final VoxelShape X_AXIS_AABB = VoxelShapes .or (PART_BASE , PART_LOWER_X , PART_MID_X , PART_UPPER_X );
35
38
36
39
@@ -41,67 +44,83 @@ public Anvil() {
41
44
.harvestLevel (1 )
42
45
.harvestTool (ToolType .PICKAXE ));
43
46
this .setRegistryName (BlacksmithMod .MODID ,"anvil" );
44
-
45
47
}
46
48
47
49
/**
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
51
53
*/
52
54
@ Override
53
55
public boolean hasTileEntity (BlockState state ) {
54
56
return true ;
55
57
}
56
58
57
59
/**
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.
62
64
*/
63
65
@ Nullable
64
66
@ Override
65
67
public TileEntity createTileEntity (BlockState state , IBlockReader world ) {
66
- return new AnvilTileEntity ();
68
+ return TileEntityRegister . ANVIL_TILE_ENTITY . create ();
67
69
}
68
70
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
+ */
69
79
@ Override
70
80
public VoxelShape getShape (BlockState state , IBlockReader worldIn , BlockPos pos , ISelectionContext context ) {
71
-
72
81
return X_AXIS_AABB ;
73
82
}
74
83
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
+ */
75
94
@ Override
76
95
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 ;
83
101
}
84
- return ActionResultType .SUCCESS ;
102
+ return ActionResultType .PASS ;
85
103
}
86
104
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
+ */
88
112
@ Override
89
113
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
92
116
player .inventory .getCurrentItem ().getItem ().setDamage (player .inventory .getCurrentItem (),1 );
93
117
TileEntity tileEntity = worldIn .getTileEntity (pos );
94
- if (tileEntity instanceof AnvilTileEntity ){
95
-
118
+ if (tileEntity instanceof AnvilTileEntity )
96
119
((AnvilTileEntity ) tileEntity ).addHit ();
97
- }
98
- }
99
- }
100
120
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 );
103
123
}
104
-
105
-
106
124
}
125
+
107
126
}
0 commit comments