Tutorials/Beginner Tutorial 1: Your First Block

From Minecraft Forge
Jump to: navigation, search

How-To Icon.png

This is a How-To guide or Tutorial detailing a practice or process for Minecraft Forge or related software.

Information Icon.png

This page was made with Minecraft Forge "v3.4.9.171" is not in the list of possible values (10.12.1.1084, 10.12.1.1083, 10.12.1.1082, 10.12.1.1081, 10.12.1.1080, 10.12.1.1079, 10.12.1.1078, 10.12.1.1077, 10.12.1.1076, 10.12.1.1075, 10.12.1.1074, 10.12.1.1073, 10.12.1.1072, 10.12.1.1071, 10.12.1.1070, 10.12.1.1069, 10.12.1.1068, 10.12.1.1067, 10.12.1.1066, 10.12.1.1065, 10.12.1.1063, 10.12.1.1061, 10.12.1.1060, 10.12.0.1059, 10.12.0.1058, 10.12.0.1057, 10.12.0.1056, 10.12.0.1055, 10.12.0.1054, 10.12.0.1053, 10.12.0.1052, 10.12.0.1051, 10.12.0.1050, 10.12.0.1049, 10.12.0.1048, 10.12.0.1047, 10.12.0.1046, 10.12.0.1045, 10.12.0.1044, 10.12.0.1043, 10.12.0.1042, 10.12.0.1041, 10.12.0.1040, 10.12.0.1039, 10.12.0.1034, 10.12.0.1033, 10.12.0.1032, 10.12.0.1031, 10.12.0.1030, 10.12.0.1029, 10.12.0.1028, 10.12.0.1027, 10.12.0.1026, 10.12.0.1025, 10.12.0.1024, 10.12.0.1023, 10.12.0.1022, 10.12.0.1021, 10.12.0.1020, 10.12.0.1019, 10.12.0.1018, 10.12.0.1017, 10.12.0.1016, 10.12.0.1015, 10.12.0.1014, 10.12.0.1013, 10.12.0.1012, 10.12.0.1011, 10.12.0.1010, 10.12.0.1009, 10.12.0.1008, 10.12.0.1007, 10.12.0.1006, 10.12.0.1005, 10.12.0.1004, 10.12.0.1003, 10.12.0.1002, 10.12.0.1001, 10.12.0.1000, 10.12.0.999, 10.12.0.998, 10.12.0.997, 10.12.0.996, 10.12.0.995, 10.12.0.994, 10.12.0.993, 10.12.0.991, 10.12.0.990, 10.12.0.989, 10.12.0.987, 10.12.0.986, 10.12.0.985, 10.12.0.984, 10.12.0.982, 10.12.0.981, 10.12.0.980, 10.12.0.979, 10.12.0.977, 10.12.0.976, 10.12.0.975, 10.12.0.974, 10.12.0.973, 10.12.0.972, 10.12.0.971, 10.12.0.970, 10.12.0.969, 10.12.0.968, 10.12.0.967, 9.11.1.965, 9.11.1.964, 9.11.1.963, 9.11.1.961, 9.11.1.960, 9.11.1.953, 9.11.1.952, 9.11.1.951, 9.11.1.949, 9.11.1.948, 9.11.1.947, 9.11.1.946, 9.11.1.945, 9.11.1.944, 9.11.1.943, 9.11.1.942, 9.11.1.941, 9.11.1.940, 9.11.1.939, 9.11.1.938, 9.11.1.937, 9.11.1.935, 9.11.1.934, 9.11.1.933, 9.11.1.931, 9.11.1.930, 9.11.1.928, 9.11.1.926, 9.11.1.925, 9.11.1.924, 9.11.1.923, 9.11.1.922, 9.11.1.921, 9.11.1.920, 9.11.1.919, 9.11.1.918, 9.11.1.917, 9.11.1.916, 9.11.1.915, 9.11.1.914, 9.11.0.913, 9.11.0.912, 9.11.0.911, 9.11.0.910, 9.11.0.909, 9.11.0.908, 9.11.0.907, 9.11.0.906, 9.11.0.905, 9.11.0.904, 9.11.0.903, 9.11.0.902, 9.11.0.901, 9.11.0.900, 9.11.0.899, 9.11.0.898, 9.11.0.897, 9.11.0.896, 9.11.0.895, 9.11.0.894, 9.11.0.893, 9.11.0.892, 9.11.0.891, 9.11.0.886, 9.11.0.885, 9.11.0.884, 9.11.0.883, 9.11.0.882, 9.11.0.881, 9.11.0.880, 9.11.0.879, 9.11.0.878, 9.11.0.877, 9.11.0.876, 9.11.0.875, 9.11.0.874, 9.11.0.873, 9.10.1.871, 9.10.1.870, 9.10.1.869, 9.10.1.867, 9.10.1.866, 9.10.1.865, 9.10.1.864, 9.10.1.863, 9.10.1.862, 9.10.1.861, 9.10.1.860, 9.10.1.859, 9.10.1.858, 9.10.1.857, 9.10.1.856, 9.10.1.855, 9.10.1.854, 9.10.1.853, 9.10.1.852, 9.10.1.851, 9.10.1.850, 9.10.1.849, 9.10.0.848, 9.10.0.847, 9.10.0.846, 9.10.0.845, 9.10.0.844, 9.10.0.843, 9.10.0.842, 9.10.0.841, 9.10.0.840, 9.10.0.839, 9.10.0.838, 9.10.0.837, 9.10.0.836, 9.10.0.835, 9.10.0.834, 9.10.0.833, 9.10.0.832, 9.10.0.831, 9.10.0.830, 9.10.0.829, 9.10.0.828, 9.10.0.827, 9.10.0.826, 9.10.0.825, 9.10.0.824, 9.10.0.823, 9.10.0.822, 9.10.0.821, 9.10.0.820, 9.10.0.819, 9.10.0.818, 9.10.0.817, 9.10.0.816, 9.10.0.804, 9.10.0.803, 9.10.0.802, 9.10.0.801, 9.10.0.800, 9.10.0.799, 9.10.0.798, 9.10.0.797, 9.10.0.796, 9.10.0.795, 9.10.0.794, 9.10.0.793, 9.10.0.792, 9.10.0.791, 9.10.0.790, 9.10.0.789, 9.10.0.787, 9.10.0.786, 9.10.0.785, 9.10.0.784, 9.10.0.781, 9.10.0.780, 9.10.0.779, 9.10.0.778, 9.10.0.777, 9.10.0.776, 8.9.0.775, 8.9.0.774, 8.9.0.773, 8.9.0.772, 8.9.0.771, 8.9.0.768, 8.9.0.767, 8.9.0.766, 8.9.0.765, 8.9.0.764, 8.9.0.763, 8.9.0.762, 8.9.0.761, 8.9.0.760, 8.9.0.759, 8.9.0.758, 8.9.0.757, 8.9.0.756, 8.9.0.755, 8.9.0.753, 8.9.0.751, 8.9.0.749, 7.8.1.738, 7.8.1.737, 7.8.0.736, 7.8.0.735, 7.8.0.734, 7.8.0.733, 7.8.0.732, 7.8.0.731, 7.8.0.730, 7.8.0.729, 7.8.0.728, 7.8.0.727, 7.8.0.726, 7.8.0.725, 7.8.0.723, 7.8.0.722, 7.8.0.721, 7.8.0.720, 7.8.0.719, 7.8.0.716, 7.8.0.715, 7.8.0.713, 7.8.0.712, 7.8.0.711, 7.8.0.710, 7.8.0.708, 7.8.0.707, 7.8.0.706, 7.8.0.705, 7.8.0.704, 7.8.0.703, 7.8.0.702, 7.8.0.701, 7.8.0.700, 7.8.0.699, 7.8.0.698, 7.8.0.697, 7.8.0.696, 7.8.0.695, 7.8.0.694, 7.8.0.693, 7.8.0.692, 7.8.0.691, 7.8.0.690, 7.8.0.689, 7.8.0.688, 7.8.0.687, 7.8.0.686, 7.8.0.685, 7.8.0.684, 7.7.2.682, 7.7.2.679, 7.7.2.678, 7.7.1.676, 7.7.1.675, 7.7.1.674, 7.7.1.673, 7.7.1.672, 7.7.1.667, 7.7.1.666, 7.7.1.665, 7.7.1.664, 7.7.1.663, 7.7.1.662, 7.7.1.661, 7.7.1.660, 7.7.1.659, 7.7.1.657, 7.7.1.656, 7.7.1.655, 7.7.1.654, 7.7.1.653, 7.7.1.652, 7.7.1.651, 7.7.1.650, 7.7.1.649, 7.7.1.648, 7.7.1.647, 7.7.1.646, 7.7.1.645, 7.7.1.644, 7.7.1.643, 7.7.1.642, 7.7.1.640, 7.7.1.639, 7.7.1.638, 7.7.1.637, 7.7.1.636, 7.7.1.635, 7.7.1.634, 7.7.1.633, 7.7.1.632, 7.7.1.631, 7.7.1.630, 7.7.1.629, 7.7.1.628, 7.7.1.627, 7.7.1.625, 7.7.1.624, 7.7.1.623, 7.7.1.622, 7.7.1.621, 7.7.1.620, 7.7.1.618, 7.7.1.617, 7.7.1.616, 7.7.1.615, 7.7.1.614, 7.7.1.611, 7.7.0.610, 7.7.0.609, 7.7.0.608, 7.7.0.605, 7.7.0.604, 7.7.0.603, 7.7.0.602, 7.7.0.601, 7.7.0.600, 7.7.0.598, 7.7.0.595, 7.7.0.594, 7.7.0.593, 7.7.0.592, 7.7.0.591, 7.7.0.590, 7.7.0.589, 7.7.0.588, 7.7.0.587, 7.7.0.586, 7.7.0.585, 7.7.0.584, 7.7.0.583, 7.7.0.582, 7.7.0.581, 7.7.0.580, 7.7.0.579, 7.7.0.578, 7.7.0.577, 7.7.0.576, 7.7.0.575, 7.7.0.574, 7.7.0.573, 7.7.0.572, 7.7.0.571, 7.7.0.569, 7.7.0.568, 7.7.0.567, 7.7.0.566, 7.7.0.565, 7.7.0.563, 7.7.0.562, 7.7.0.561, 7.7.0.560, 7.7.0.559, 6.6.2.534, 6.6.2.533, 6.6.1.532, 6.6.1.531, 6.6.1.530, 6.6.1.529, 6.6.1.528, 6.6.1.527, 6.6.1.524, 6.6.1.523, 6.6.1.522, 6.6.1.521, 6.6.0.518, 6.6.0.517, 6.6.0.516, 6.6.0.515, 6.6.0.511, 6.6.0.510, 6.6.0.509, 6.6.0.507, 6.6.0.506, 6.6.0.505, 6.6.0.504, 6.6.0.503, 6.6.0.502, 6.6.0.501, 6.6.0.499, 6.6.0.497, 6.6.0.496, 6.6.0.495, 6.6.0.494, 6.6.0.493, 6.6.0.492, 6.6.0.491, 6.6.0.490, 6.5.0.489, 6.5.0.488, 6.5.0.487, 6.5.0.486, 6.5.0.484, 6.5.0.483, 6.5.0.482, 6.5.0.481, 6.5.0.480, 6.5.0.479, 6.5.0.478, 6.5.0.477, 6.5.0.476, 6.5.0.475, 6.5.0.474, 6.5.0.473, 6.5.0.472, 6.5.0.471, 6.5.0.470, 6.5.0.469, 6.5.0.468, 6.5.0.467, 6.5.0.466, 6.5.0.465, 6.5.0.464, 6.5.0.463, 6.5.0.462, 6.5.0.461, 6.5.0.460, 6.5.0.459, 6.5.0.458, 6.5.0.457, 6.5.0.456, 6.5.0.455, 6.5.0.454, 6.5.0.453, 6.5.0.452, 6.5.0.451, 6.4.2.448, 6.4.2.447, 6.4.2.446, 6.4.2.445, 6.4.2.444, 6.4.2.443, 6.4.1.442, 6.4.1.441, 6.4.1.439, 6.4.1.438, 6.4.1.437, 6.4.1.436, 6.4.1.435, 6.4.1.434, 6.4.1.433, 6.4.1.432, 6.4.1.430, 6.4.1.428, 6.4.1.426, 6.4.1.425, 6.4.1.424, 6.4.1.416, 6.4.1.414, 6.4.1.413, 6.4.1.411, 6.4.1.410, 6.4.1.409, 6.4.1.408, 6.4.1.407, 6.4.1.406, 6.4.1.405, 6.4.1.404, 6.4.1.403, 6.4.1.402, 6.4.1.401, 6.4.1.400, 6.4.0.399, 6.4.0.398, 6.4.0.397, 6.4.0.396, 6.4.0.395, 6.4.0.394, 6.4.0.393, 6.4.0.390, 6.4.0.388, 6.4.0.387, 6.4.0.386, 6.4.0.385, 6.4.0.384, 6.4.0.383, 6.4.0.382, 6.4.0.381, 6.4.0.380, 6.4.0.379, 6.3.0.378, 6.3.0.377, 6.3.0.376, 6.3.0.375, 6.3.0.374, 6.3.0.373, 6.3.0.372, 6.3.0.371, 6.3.0.370, 6.3.0.369, 6.3.0.368, 6.3.0.367, 6.3.0.366, 6.3.0.365, 6.3.0.364, 6.3.0.363, 6.3.0.362, 6.3.0.361, 6.3.0.360, 6.2.1.358, 6.2.1.357, 6.2.1.356, 6.0.1.355, 6.0.1.354, 6.0.1.353, 6.0.1.351, 6.0.1.350, 6.0.1.349, 6.0.1.348, 6.0.1.347, 6.0.1.345, 6.0.1.343, 6.0.1.342, 6.0.1.341, 6.0.1.339, 6.0.1.338, 6.0.1.337, 6.0.1.336, 6.0.1.332, 6.0.1.331, 6.0.1.330, 6.0.0.329, 6.0.0.328, 6.0.0.327, 5.0.0.326, 5.0.0.325, 5.0.0.324, 5.0.0.323, 5.0.0.322, 5.0.0.321, 5.0.0.320, 4.3.5.318, 4.2.5.317, 4.2.5.316, 4.2.5.315, 4.2.5.314, 4.2.5.313, 4.2.5.312, 4.2.5.311, 4.2.5.310, 4.2.5.307, 4.2.5.306, 4.2.5.305, 4.2.5.303, 4.2.5.302, 4.2.5.301, 4.2.5.300, 4.2.5.299, 4.1.4.298, 4.1.4.297, 4.1.4.296, 4.1.4.295, 4.1.4.294, 4.1.4.292, 4.1.4.291, 4.1.4.290, 4.1.4.289, 4.1.4.288, 4.1.4.287, 4.1.4.286, 4.1.4.285, 4.1.4.284, 4.1.4.282, 4.1.4.281, 4.1.4.280, 4.1.4.279, 4.1.4.278, 4.1.4.277, 4.1.4.276, 4.1.4.275, 4.1.4.274, 4.1.4.272, 4.1.4.271, 4.1.3.270, 4.1.2.269, 4.1.2.268, 4.1.2.267, 4.1.2.266, 4.1.2.265, 4.1.2.264, 4.1.2.263, 4.1.2.262, 4.1.2.261, 4.1.2.260, 4.1.2.259, 4.1.1.258, 4.1.1.257, 4.1.1.256, 4.1.1.255, 4.1.1.254, 4.1.1.253, 4.1.1.252, 4.1.1.251, 4.0.0.250, 4.0.0.249, 4.0.0.248, 4.0.0.247, 4.0.0.246, 4.0.0.245, 4.0.0.243, 4.0.0.242, 4.0.0.241, 4.0.0.240, 4.0.0.239, 4.0.0.238, 4.0.0.237, 4.0.0.236, 4.0.0.235, 4.0.0.234, 4.0.0.233, 4.0.0.232, 4.0.0.231, 4.0.0.230, 4.0.0.229, 4.0.0.228, 4.0.0.227, 4.0.0.226, 4.0.0.225, 4.0.0.224, 4.0.0.223, 4.0.0.222, 4.0.0.221, 4.0.0.220, 4.0.0.217, 4.0.0.216, 4.0.0.215, 4.0.0.214, 4.0.0.213, 4.0.0.212, 4.0.0.211, 4.0.0.210, 4.0.0.209, 4.0.0.208, 4.0.0.207, 4.0.0.206, 4.0.0.205, 4.0.0.204, 4.0.0.200, 4.0.0.199, 4.0.0.198, 4.0.0.197, 4.0.0.196, 4.0.0.195, 4.0.0.194, 4.0.0.193, 4.0.0.192, 4.0.0.191, 4.0.0.190, 4.0.0.189, 4.0.0.188, 4.0.0.187, 4.0.0.186, 4.0.0.185, 4.0.0.184, 4.0.0.183, 4.0.0.182, 4.0.0.181, 4.0.0.180, 4.0.0.179, 4.0.0.178, 4.0.0.177, 4.0.0.176, 4.0.0.173, 4.0.0.172, 3.4.9.171, 3.3.8.170, 3.3.8.168, 3.3.8.164, 3.3.8.163, 3.3.8.162, 3.3.8.161, 3.3.8.160, 3.3.8.159, 3.3.8.158, 3.3.8.157, 3.3.8.156, 3.3.8.155, 3.3.8.154, 3.3.8.153, 3.3.8.152, 3.3.8.151, 3.3.8.150, 3.3.8.148, 3.3.8.147, 3.3.8.146, 3.3.8.145, 3.3.8.144, 3.3.8.143, 3.3.8.142, 3.3.8.141, 3.3.7.140, 3.3.7.139, 3.3.7.138, 3.3.7.137, 3.3.7.136, 3.3.7.135, 3.3.7.134, 3.3.7.133, 3.2.6.132, 3.2.6.131, 3.2.6.130, 3.2.6.129, 3.2.5.128, 3.2.5.127, 3.2.5.126, 3.2.5.125, 3.2.5.124, 3.2.5.123, 3.2.5.122, 3.2.5.121, 3.2.5.120, 3.2.5.119, 3.2.5.118, 3.2.5.117, 3.2.4.116, 3.2.4.115, 3.2.4.114, 3.2.4.111, 3.2.4.110, 3.2.3.108, 3.1.3.107, 3.1.3.106, 3.1.3.105, 3.1.3.104, 3.1.3.103, 3.1.3.102, 3.1.3.101, 3.1.3.100, 3.1.3.99, 3.1.2.98, 3.1.2.97, 3.1.2.96, 3.1.2.95, 3.1.2.94, 3.1.2.93, 3.1.2.92, 3.1.2.91, 3.1.2.90, 3.0.1.89, 3.0.1.88, 3.0.1.87, 3.0.1.86, 3.0.1.85, 3.0.1.84, 3.0.1.83, 3.0.1.82, 3.0.1.81, 3.0.1.80, 3.0.1.79, 3.0.1.78, 3.0.1.77, 3.0.1.75, 3.0.1.74, 3.0.1.73, 3.0.0.72, 3.0.0.71, 3.0.0.70, 3.0.0.69, 2.0.0.68, 2.0.0.67, 2.0.0.66, 2.0.0.65, 1.4.1.64, 1.4.1.63, 1.4.1.62, 1.4.1.61, 1.4.1.60, 1.4.1.59, 1.4.1.58, 1.4.0.57, 1.4.0.56, 1.4.0.55, 1.4.0.52, 1.4.0.51, 1.4.0.50, 1.4.0.48, 1.4.0.47, 1.4.0.46, 1.4.0.45, 1.4.0.44, 1.3.4.41, 1.3.4.39, 1.3.4.38, 1.3.4.37, 1.3.4.36, 1.3.4.35, 1.3.4.34, 1.3.4.33, 1.3.4.32, 1.3.4.31, 1.3.4.30, 1.3.4.29, 1.3.3.28, 1.3.3.27, 1.3.3.26, 1.3.3.24, 1.3.3.23, 1.3.3.22, 1.3.3.21, 1.3.3.20, 1.3.3.19, 1.3.3.18, 1.3.3.16, 1.3.3.15, 1.3.3.14, 1.3.3.13, 1.3.3.12, 1.3.2.10, 1.3.2.9, 1.3.2.8, 1.3.2.7, 1.3.2.6, 1.3.2.5, 1.3.2.4, 1.3.2.3, 1.3.2.2, 1.3.2.1, 10.12.1.1085, 10.12.1.1097, 10.12.1.1096, 10.12.1.1095, 10.12.1.1094, 10.12.1.1093, 10.12.1.1092, 10.12.1.1091, 10.12.1.1090, 10.12.1.1088, 10.12.1.1087, 10.12.1.1099, 10.12.1.1098, 10.12.1.1103, 10.12.1.1101, 10.12.1.1100, 10.12.1.1110, 10.12.1.1109, 10.12.1.1108, 10.12.1.1107, 10.12.1.1106, 10.12.1.1105, 10.12.1.1104, 10.12.1.1111, 10.12.1.1112, 10.12.1.1117, 10.12.1.1116, 10.12.1.1115, 10.12.1.1114, 10.12.1.1113, 10.12.1.1119, 10.12.1.1118, 10.12.2.1125, 10.12.2.1124, 10.12.2.1123, 10.12.2.1122, 10.12.2.1121, 10.12.2.1120, 10.12.2.1127, 10.12.2.1126, 10.12.2.1133, 10.12.2.1132, 10.12.2.1131, 10.12.2.1130, 10.12.2.1129, 10.12.2.1128, 10.12.2.1155, 10.12.2.1154, 10.12.2.1147, 10.12.2.1145, 10.13.0.1158, 10.13.0.1157, 10.13.0.1156, 10.13.0.1153, 10.13.0.1152, 10.13.0.1151, 10.13.0.1150, 10.12.2.1149, 10.12.2.1148, 10.12.2.1146, 10.12.2.1144, 10.12.2.1143, 10.12.2.1142, 10.12.2.1141, 10.12.2.1139, 10.12.2.1138, 10.12.2.1137) for this property.. It might not work with other versions.

Warning Icon.png

This page is marked for Deletion. It is no longer relevant, needed, or is a result of an error or issue. Only certain users with appropriate rights will be able to delete this page.


Warning Icon.png

This page uses the ModLoader compatibility classes rather then the Forge and FML APIs and Interfaces. The compatibility classes are only added to give compatibility with ModLoader mods and should not be used. Please help improve this article if you can.

Warning Icon.png

This page is marked as Outdated.

It was made for older content and may cause problems.

Please improve this article if you can.


This tutorial is in the process of being updated to the newest version of FML and Forge on a google doc file and will be posted once done. If you want to take a quick look you can find it here, you can leave comments but please keep these to information on how to improve the page only.

Welcome to the beginner tutorial series, in this series you will learn the basics of creating minecraft mods. This tutorial assumes you have MCP62, Minecraft 1.2.5, Forge v3.4.9.171 and Eclipse ready with the code decompiled. Other versions should work about the same but won't work guaranteed. It also assumes you have basic knowledge of Java.

If you find errors, typos or other problems in this tutorial, not including coding style, feel free to correct them or post them on the discussion page to be corrected.


Contents

Introduction

In this tutorial you will create a mod project and a simple block that reacts to right-clicking. You will create classes for your mod and the block. Additionally you will recompile and run the game with your mod installed. At the time of writing, the minecraft_server.jar was not available for 1.2.5 and was therefore not decompiled.


Creating Your Mod

With Eclipse open and the code ready, start out by creating a new package for your mod in the Client project to keep your files organized and your classes separated. For this example I'm gonna name it "net.minecraft.src.tutorial".

In your new package, create a new class with your mod as name and with the prefix "mod_". For this example I'm going with "mod_Tutorial". While it does not follow Java naming conventions, this is needed for ModLoader to find your mod.

The new Java file should look something like this:

package net.minecraft.src.tutorial;

public class mod_Tutorial
{

}

First thing to do is to make your plain class extend the "NetworkMod" class, this will give you the basic functionality ModLoader needs to load your mod and import the class to your file.

Add the following code above your class definition.

import net.minecraft.src.forge.NetworkMod;

Change your class definition to the following.

public class mod_Tutorial extends NetworkMod

You will get a warning about unimplemented methods, which we will add now. Add the following code in your class.

@Override
public String getVersion()
{
        return "Tutorial Mod 1.0.0";
}

This method will be called by ModLoader and will be displayed in the log and the Mods menu in Minecraft's main menu. Not all required methods have been added yet, so add the following code right after your getVersion() function.

@Override
public void load()
{
       
}

This method will be called by ModLoader when your mod needs to load, so we will put everything that has to load at the start of the mod here.

Congratulations, you now have a fully working bare bones mod that does absolutely nothing. Before we continue, here is the full source code of what we have so far.


mod_Tutorial.java

package net.minecraft.src.tutorial;

import net.minecraft.src.forge.NetworkMod;

public class mod_Tutorial extends NetworkMod
{
        @Override
        public String getVersion()
        {
                return "Tutorial Mod 1.0.0";
        }
       
        @Override
        public void load()
        {
               
        }
}

Creating Your Block

So your mod loads correctly now, but you probably want it to actually do something. In this part of the tutorial we are going to add a simple block using default Minecraft textures.

First, create a new class again in your package. This time, call it what you want your block to be called prefixed with "Block". This isn't required, but useful for keeping your code clean. In this example I'm going to call it "BlockHelloWorld".

Change your class definition so it extends the class "Block" and add the import for that class. Your block's java file will now look something like this:

package net.minecraft.src.tutorial;

import net.minecraft.src.Block;

public class BlockHelloWorld extends Block
{

}

You will again have a warning that you are missing a method required to extend the class, so let's add that next.

Add the following line to your imports.

import net.minecraft.src.Material;

Add the following code to your block's class.

public BlockHelloWorld(int blockID)
{
        super(blockID, Material.wood);
}

Because the name of the function is the same as the class it will be the constructor. You can read more about constructors somewhere else, I'm not going to further explain it in this tutorial. The super function simply calls the constructor of the class your block's class extends.

Using the constructor from the original Block class, we tell Minecraft that your block has to have the ID given to it using the constructor and the Material "wood". We use the constructor to get the ID because you might want to add a flexible configuration file to your mod that changes what ID is used.

You now have a very basic block, but it doesn't actually have any data for what textures it should use, how hard it is and what sound it makes when you walk over it. We're going to add those now.

Add the following code to the constructor, right below "super(blockID, Material.wood);"

blockIndexInTexture = 1;
setHardness(2.0f);
setResistance(5.0f);
setStepSound(soundWoodFootstep);

setBlockName("Hello World Block");

The blockIndexInTexture variable tells Minecraft what the index is of the texture that will be used for your block. You can override this behavior for specific sides in a different function, but we'll get to that later on. For this example I'm using the index of stone in the standard terrain.png.

The setHardness function sets the hardness of the block, meaning how long it takes to mine the block.

The setResistance function sets the resistence of the block, meaning how much it reduces the blast of TNT and how strong the blast has to be to break it.

The setStepSound function sets the sound your footsteps will make on the block.

The setBlockName function tells minecraft to look up the name of the block in localization data, we will later use ModLoader to directly give it a name instead so we don't have to worry about adding that information yet.

We haven't yet told Minecraft what texture file we'll be using, so let's do that now. Add the following code to the bottom of your class.

@Override
public String getTextureFile()
{
        return "/terrain.png";
}

Since we'll just be using the default textures we'll just use "terrain.png".

Now that we have basic information about the block itself and the texture the block should be ready to be added to the mod class itself, but first we want to do a little tweak to the texture. Rather than leaving the block looking like stone, we'll want to change the top and bottom of the block to the texture of the top and bottom of logs which have a texture index of 21.

To do this, add the following function to your class.

@Override
public int getBlockTextureFromSide(int side)
{
        switch(side)
        {
        case 0:
                return 21;
        case 1:
                return 21;
        }
        return blockIndexInTexture;
}

Using this you override the default functionality of Minecraft, which is to give each side the texture with the index of blockIndexInTexture, and instead return the index of logs when the side requested is the top or the bottom.

Before we continue, here is the code of your block so far.


BlockHelloWorld.java

package net.minecraft.src.tutorial;

import net.minecraft.src.Block;
import net.minecraft.src.Material;

public class BlockHelloWorld extends Block
{
        public BlockHelloWorld(int blockID)
    {
                super(blockID, Material.wood);
               
                blockIndexInTexture = 1;
        setHardness(2.0f);
        setResistance(5.0f);
        setStepSound(soundWoodFootstep);
       
        setBlockName("Hello World Block");
    }
       
        @Override
        public int getBlockTextureFromSide(int side)
        {
                switch(side)
                {
                case 0:
                        return 21;
                case 1:
                        return 21;
                }
                return blockIndexInTexture;
        }
       
        @Override
        public String getTextureFile()
        {
                return "/terrain.png";
        }
}

Adding the Block to Minecraft

Now that all the information for the block and the texture is there, we can register it to ModLoader and add the recipes. First, back in mod_Tutorial add the following code to the imports.

import net.minecraft.src.Block;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.ModLoader;

At the top of your class, add the following code.

// Block Definitions
public Block blockHelloWorld;

We'll use this to store your block definition so we can tell ModLoader to add the block to the game and to add recipes for and with it.

Go to your load() function and add the following code.

blockHelloWorld = new BlockHelloWorld(160);

// Register Blocks
ModLoader.registerBlock(blockHelloWorld);

// Add Recipes
ModLoader.addRecipe(new ItemStack(blockHelloWorld, 3), new Object[]
{
        "   ", "X+X", "   ", 'X', Block.stone, '+', Block.wood
});

// Add Names
ModLoader.addName(blockHelloWorld, "Hello World Block");

First we initialize the block and give it the ID 160. If you got your own configuration system, use that to get the ID for your block, otherwise just use this.

We then register the block using ModLoader, which adds it to the game. After that we add a recipe to craft the block and lastly we add the name that will be displayed for the block.

And then we're done! Just run recompile.bat and then startclient.bat and you can craft your new block and place it! In the next tutorial we'll look into some more functionality, but for now we're done.

Here is one last time the complete code of everything.


mod_Tutorial.java

package net.minecraft.src.tutorial;

import net.minecraft.src.Block;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.ModLoader;
import net.minecraft.src.forge.NetworkMod;

public class mod_Tutorial extends NetworkMod
{
        // Block Definitions
        public Block blockHelloWorld;
       
        @Override
        public String getVersion()
        {
                return "Tutorial Mod 1.0.0";
        }
       
        @Override
        public void load()
        {
                blockHelloWorld = new BlockHelloWorld(160);
               
                // Register Blocks
                ModLoader.registerBlock(blockHelloWorld);
               
                // Add Recipes
                ModLoader.addRecipe(new ItemStack(blockHelloWorld, 3), new Object[]
                {
                        "   ", "X+X", "   ", 'X', Block.stone, '+', Block.wood
                });
               
                // Add Names
                ModLoader.addName(blockHelloWorld, "Hello World Block");
        }
}


BlockHelloWorld.java

package net.minecraft.src.tutorial;

import net.minecraft.src.Block;
import net.minecraft.src.Material;

public class BlockHelloWorld extends Block
{
        public BlockHelloWorld(int blockID)
    {
                super(blockID, Material.wood);
               
                blockIndexInTexture = 1;
        setHardness(2.0f);
        setResistance(5.0f);
        setStepSound(soundWoodFootstep);
       
        setBlockName("Hello World Block");
    }
       
        @Override
        public int getBlockTextureFromSide(int side)
        {
                switch(side)
                {
                case 0:
                        return 21;
                case 1:
                        return 21;
                }
                return blockIndexInTexture;
        }
       
        @Override
        public String getTextureFile()
        {
                return "/terrain.png";
        }
}
Personal tools
Namespaces
Variants
Actions
Navigation
tutorials
Toolbox