@@ -85,29 +85,58 @@ private void harvestTick() {
85
85
int Z = (int ) Math .floor (p .posZ );
86
86
for (int deltaX = -range ; deltaX <= range ; ++deltaX )
87
87
for (int deltaZ = -range ; deltaZ <= range ; ++deltaZ ) {
88
- BlockPos pos = new BlockPos (X + deltaX , Y , Z + deltaZ );
89
- IBlockState state = w .getBlockState (pos );
90
- Block b = state .getBlock ();
91
- if (CropManager .isCropMature (w , pos , state , b )) {
92
- Minecraft .getMinecraft ().playerController .onPlayerDamageBlock (pos , EnumFacing .UP );
93
- return ;
88
+ for (int deltaY = -1 ; deltaY <= 1 ; ++deltaY ) {
89
+ BlockPos pos = new BlockPos (X + deltaX , Y + deltaY , Z + deltaZ );
90
+ IBlockState state = w .getBlockState (pos );
91
+ Block b = state .getBlock ();
92
+ if (CropManager .isCropMature (w , pos , state , b )) {
93
+ Minecraft .getMinecraft ().playerController .onPlayerDamageBlock (pos , EnumFacing .UP );
94
+ return ;
95
+ }
94
96
}
95
97
}
96
98
}
97
99
100
+ private void minusOneInHand () {
101
+ ItemStack st = p .getHeldItem (EnumHand .MAIN_HAND );
102
+ if (st != null ) {
103
+ if (st .stackSize <= 1 ) {
104
+ p .setHeldItem (EnumHand .MAIN_HAND , null );
105
+ } else {
106
+ st .stackSize --;
107
+ }
108
+ }
109
+ }
110
+
98
111
private ItemStack lastUsedItem = null ;
99
112
100
113
private ItemStack tryFillItemInHand () {
101
114
ItemStack itemStack = p .getHeldItem (EnumHand .MAIN_HAND );
102
115
if (itemStack == null ) {
103
- // TODO
104
- AutoHarvest .msg ("notify.lack_of_seed" );
105
- AutoHarvest .msg ("notify.switch_to.off" );
106
- AutoHarvest .instance .toNextMode (AutoHarvest .HarvestMode .OFF );
107
- lastUsedItem = null ;
108
- return null ;
116
+ int supplmentIdx = -1 ;
117
+ ItemStack stack = null ;
118
+ if (lastUsedItem != null ) {
119
+ ItemStack [] inv = p .inventory .mainInventory ;
120
+ for (int idx = 0 ; idx < 36 ; ++idx ) {
121
+ if (inv [idx ] != null && inv [idx ].getItem () == lastUsedItem .getItem () &&
122
+ inv [idx ].getItemDamage () == lastUsedItem .getItemDamage () &&
123
+ inv [idx ].hasTagCompound () == false ) {
124
+ supplmentIdx = idx ;
125
+ stack = inv [idx ];
126
+ break ;
127
+ }
128
+ }
129
+ }
130
+ if (supplmentIdx < 0 ) {
131
+ AutoHarvest .msg ("notify.lack_of_seed" );
132
+ AutoHarvest .msg ("notify.switch_to.off" );
133
+ AutoHarvest .instance .toNextMode (AutoHarvest .HarvestMode .OFF );
134
+ lastUsedItem = null ;
135
+ return null ;
136
+ }
137
+ AutoHarvest .moveInventoryItem (supplmentIdx , p .inventory .currentItem );
138
+ return stack ;
109
139
} else {
110
- lastUsedItem = null ;
111
140
return itemStack ;
112
141
}
113
142
}
@@ -117,12 +146,10 @@ private void plantTick() {
117
146
if (handItem == null ) return ;
118
147
if (!CropManager .isSeed (handItem )) {
119
148
if (CropManager .isCocoa (handItem )) {
120
- lastUsedItem = handItem ;
121
- plantCocoaTick ();
149
+ plantCocoaTick (handItem );
122
150
}
123
151
return ;
124
152
}
125
- lastUsedItem = handItem ;
126
153
127
154
World w = p .worldObj ;
128
155
int X = (int ) Math .floor (p .posX );
@@ -141,12 +168,94 @@ private void plantTick() {
141
168
handItem , downPos , EnumFacing .UP ,
142
169
new Vec3d (X + deltaX + 0.5 , Y , Z + deltaZ + 0.5 ),
143
170
EnumHand .MAIN_HAND );
171
+ lastUsedItem = handItem ;
172
+ minusOneInHand ();
144
173
}
145
174
}
146
175
}
147
176
148
- private void plantCocoaTick () {
149
- // TODO
177
+ private void plantCocoaTick (ItemStack handItem ) {
178
+ World w = p .worldObj ;
179
+ int X = (int ) Math .floor (p .posX );
180
+ int Y = (int ) Math .floor (p .posY + 0.2D );//the "leg block" , in case in soul sand
181
+ int Z = (int ) Math .floor (p .posZ );
182
+
183
+ for (int deltaX = -range ; deltaX <= range ; ++deltaX ) {
184
+ for (int deltaZ = -range ; deltaZ <= range ; ++deltaZ ) {
185
+ for (int deltaY = 0 ; deltaY <= 7 ; ++deltaY ) {
186
+ BlockPos pos = new BlockPos (X + deltaX , Y + deltaY , Z + deltaZ );
187
+ if (!canReachBlock (p , pos )) continue ;
188
+ IBlockState jungleBlock = w .getBlockState (pos );
189
+ if (CropManager .isJungleLog (jungleBlock )) {
190
+ BlockPos tmpPos ;
191
+
192
+ EnumFacing tmpFace = EnumFacing .EAST ;
193
+ tmpPos = pos .add (tmpFace .getDirectionVec ());
194
+ if (w .getBlockState (tmpPos ).getBlock () == Blocks .AIR ) {
195
+ FMLClientHandler .instance ().getClient ().playerController .processRightClickBlock (
196
+ p ,
197
+ FMLClientHandler .instance ().getWorldClient (),
198
+ handItem , pos , tmpFace ,
199
+ new Vec3d (X + deltaX + 1 , Y + deltaY + 0.5 , Z + deltaZ + 0.5 ),
200
+ EnumHand .MAIN_HAND );
201
+ lastUsedItem = handItem ;
202
+ minusOneInHand ();
203
+ return ;
204
+ }
205
+
206
+ tmpFace = EnumFacing .WEST ;
207
+ tmpPos = pos .add (tmpFace .getDirectionVec ());
208
+ if (w .getBlockState (tmpPos ).getBlock () == Blocks .AIR ) {
209
+ FMLClientHandler .instance ().getClient ().playerController .processRightClickBlock (
210
+ p ,
211
+ FMLClientHandler .instance ().getWorldClient (),
212
+ handItem , pos , tmpFace ,
213
+ new Vec3d (X + deltaX , Y + deltaY + 0.5 , Z + deltaZ + 0.5 ),
214
+ EnumHand .MAIN_HAND );
215
+ lastUsedItem = handItem ;
216
+ minusOneInHand ();
217
+ return ;
218
+ }
219
+
220
+ tmpFace = EnumFacing .SOUTH ;
221
+ tmpPos = pos .add (tmpFace .getDirectionVec ());
222
+ if (w .getBlockState (tmpPos ).getBlock () == Blocks .AIR ) {
223
+ FMLClientHandler .instance ().getClient ().playerController .processRightClickBlock (
224
+ p ,
225
+ FMLClientHandler .instance ().getWorldClient (),
226
+ handItem , pos , tmpFace ,
227
+ new Vec3d (X + deltaX + 0.5 , Y + deltaY + 0.5 , Z + deltaZ + 1 ),
228
+ EnumHand .MAIN_HAND );
229
+ lastUsedItem = handItem ;
230
+ minusOneInHand ();
231
+ return ;
232
+ }
233
+
234
+ tmpFace = EnumFacing .NORTH ;
235
+ tmpPos = pos .add (tmpFace .getDirectionVec ());
236
+ if (w .getBlockState (tmpPos ).getBlock () == Blocks .AIR ) {
237
+ FMLClientHandler .instance ().getClient ().playerController .processRightClickBlock (
238
+ p ,
239
+ FMLClientHandler .instance ().getWorldClient (),
240
+ handItem , pos , tmpFace ,
241
+ new Vec3d (X + deltaX + 0.5 , Y + deltaY + 0.5 , Z + deltaZ ),
242
+ EnumHand .MAIN_HAND );
243
+ lastUsedItem = handItem ;
244
+ minusOneInHand ();
245
+ return ;
246
+ }
247
+ }
248
+ }
249
+ }
250
+ }
251
+ }
252
+
253
+ private boolean canReachBlock (EntityPlayerSP playerEntity , BlockPos blockpos ) {
254
+ double d0 = playerEntity .posX - ((double ) blockpos .getX () + 0.5D );
255
+ double d1 = playerEntity .posY - ((double ) blockpos .getY () + 0.5D ) + 1.5D ;
256
+ double d2 = playerEntity .posZ - ((double ) blockpos .getZ () + 0.5D );
257
+ double d3 = d0 * d0 + d1 * d1 + d2 * d2 ;
258
+ return d3 <= 36D ;
150
259
}
151
260
152
261
private void feedTick () {
@@ -161,6 +270,7 @@ private void feedTick() {
161
270
FMLClientHandler .instance ().getClient ().playerController
162
271
.interactWithEntity (p , e , handItem , EnumHand .MAIN_HAND );
163
272
lastUsedItem = handItem ;
273
+ minusOneInHand ();
164
274
return ;
165
275
}
166
276
}
0 commit comments