3
3
import net .minecraft .block .Block ;
4
4
import net .minecraft .block .state .IBlockState ;
5
5
import net .minecraft .client .Minecraft ;
6
- import net .minecraft .entity .Entity ;
7
- import net .minecraft .entity .monster .EntityZombie ;
8
6
import net .minecraft .entity .passive .*;
9
7
import net .minecraft .entity .player .EntityPlayer ;
10
8
import net .minecraft .entity .player .InventoryPlayer ;
11
9
import net .minecraft .init .Blocks ;
12
10
import net .minecraft .init .Items ;
13
11
import net .minecraft .item .Item ;
14
12
import net .minecraft .item .ItemStack ;
15
- import net .minecraft .util .AxisAlignedBB ;
16
- import net .minecraft .util .BlockPos ;
17
13
import net .minecraft .util .EnumFacing ;
18
- import net .minecraft .util .Vec3 ;
14
+ import net .minecraft .util .EnumHand ;
15
+ import net .minecraft .util .math .AxisAlignedBB ;
16
+ import net .minecraft .util .math .BlockPos ;
17
+ import net .minecraft .util .math .Vec3d ;
19
18
import net .minecraft .world .World ;
20
19
import net .minecraftforge .fml .client .FMLClientHandler ;
21
- import net .minecraftforge .fml .common .FMLCommonHandler ;
22
20
import net .minecraftforge .fml .common .eventhandler .SubscribeEvent ;
23
21
import net .minecraftforge .fml .common .gameevent .TickEvent ;
24
22
import net .minecraftforge .fml .relauncher .Side ;
25
23
26
- import java .util .HashMap ;
27
24
import java .util .List ;
28
- import java .util .Map ;
29
25
30
26
public class TickListener {
31
27
private int tickCount = 0 ;
@@ -38,7 +34,6 @@ public TickListener(AutoHarvest.HarvestMode mode) {
38
34
this .mode = mode ;
39
35
}
40
36
41
- @ SuppressWarnings ("unused" )
42
37
@ SubscribeEvent
43
38
public void onTick (TickEvent .PlayerTickEvent e ) {
44
39
if (e .side == Side .CLIENT && e .player != null &&
@@ -62,10 +57,6 @@ public void onTick(TickEvent.PlayerTickEvent e) {
62
57
feedTick (e .player );
63
58
break ;
64
59
}
65
- // case ATTACK: {
66
- // attackTick(e.player);
67
- // break;
68
- // }
69
60
}
70
61
}
71
62
}
@@ -121,15 +112,15 @@ private boolean tryFillItemInHand(EntityPlayer p) {
121
112
return true ;
122
113
}
123
114
}
124
- AutoHarvest .sendI18nMsg ("notify.lack_of_seed" );
125
- AutoHarvest .sendI18nMsg ("notify.switch_to.off" );
115
+ AutoHarvest .msg ("notify.lack_of_seed" );
116
+ AutoHarvest .msg ("notify.switch_to.off" );
126
117
AutoHarvest .instance .toNextMode (AutoHarvest .HarvestMode .OFF );
127
118
128
119
return false ;
129
120
}
130
121
131
122
private void plantTick (EntityPlayer p ) {
132
- ItemStack handItem = p .getHeldItem ();
123
+ ItemStack handItem = p .getHeldItem (EnumHand . MAIN_HAND );
133
124
if (!CropManager .isSeed (handItem )) {
134
125
return ;
135
126
}
@@ -148,75 +139,56 @@ private void plantTick(EntityPlayer p) {
148
139
&& downBlock != Blocks .air
149
140
&& CropManager .canPlantOn (handItem .getItem (), w , downPos , downBlock )) {
150
141
if (handItem .stackSize <= REFILL_THRESHOLD && tryFillItemInHand (p ))
151
- handItem = p .getHeldItem ();
152
- FMLClientHandler .instance ().getClient ().playerController .onPlayerRightClick (
142
+ handItem = p .getHeldItem (EnumHand .MAIN_HAND );
143
+
144
+ FMLClientHandler .instance ().getClient ().playerController .processRightClickBlock (
153
145
FMLClientHandler .instance ().getClientPlayerEntity (),
154
146
FMLClientHandler .instance ().getWorldClient (),
155
147
handItem , downPos , EnumFacing .UP ,
156
- new Vec3 (X + deltaX + 0.5 , Y , Z + deltaZ + 0.5 ));
148
+ new Vec3d (X + deltaX + 0.5 , Y , Z + deltaZ + 0.5 ),
149
+ EnumHand .MAIN_HAND );
157
150
}
158
151
}
159
152
}
160
153
161
154
private boolean tryFeedAnimal (Class <? extends EntityAnimal > type , AxisAlignedBB box , EntityPlayer p ) {
162
155
for (EntityAnimal e : (List <EntityAnimal >) (p .getEntityWorld ().getEntitiesWithinAABB (type , box ))) {
163
156
if (e .getGrowingAge () == 0 && !e .isInLove ()) {
164
- FMLClientHandler .instance ().getClient ().playerController .interactWithEntitySendPacket (p , e );
157
+ FMLClientHandler .instance ().getClient ().playerController
158
+ .func_187097_a (p , e , p .getHeldItem (EnumHand .MAIN_HAND ), EnumHand .MAIN_HAND ); //interactWithEntity()
165
159
return true ;
166
160
}
167
161
}
168
162
return false ;
169
163
}
170
164
171
165
private void feedTick (EntityPlayer p ) {
172
- ItemStack handItem = p .getHeldItem ();
166
+ ItemStack handItem = p .getHeldItem (EnumHand . MAIN_HAND );
173
167
if (handItem == null ) return ;
174
168
if (handItem .getItem ().equals (Items .carrot )) { //pig & rabbit
175
169
if (handItem .stackSize <= REFILL_THRESHOLD ) tryFillItemInHand (p );
176
- AxisAlignedBB box = AxisAlignedBB . fromBounds (p .posX - 2 , p .posY - 1 , p .posZ - 2 , p .posX + 2 , p .posY + 3 , p .posZ + 2 );
170
+ AxisAlignedBB box = new AxisAlignedBB (p .posX - 2 , p .posY - 1 , p .posZ - 2 , p .posX + 2 , p .posY + 3 , p .posZ + 2 );
177
171
if (tryFeedAnimal (EntityPig .class , box , p )) return ;
178
172
if (tryFeedAnimal (EntityRabbit .class , box , p )) return ;
179
173
} else if (handItem .getItem ().equals (Items .wheat )) { //cow & sheep & mooshrom
180
174
if (handItem .stackSize <= REFILL_THRESHOLD ) tryFillItemInHand (p );
181
- AxisAlignedBB box = AxisAlignedBB . fromBounds (p .posX - 2 , p .posY - 1 , p .posZ - 2 , p .posX + 2 , p .posY + 3 , p .posZ + 2 );
175
+ AxisAlignedBB box = new AxisAlignedBB (p .posX - 2 , p .posY - 1 , p .posZ - 2 , p .posX + 2 , p .posY + 3 , p .posZ + 2 );
182
176
if (tryFeedAnimal (EntityCow .class , box , p )) return ;
183
177
if (tryFeedAnimal (EntityMooshroom .class , box , p )) return ;
184
178
if (tryFeedAnimal (EntitySheep .class , box , p )) return ;
185
179
} else if (handItem .getItem ().equals (Items .wheat_seeds )) { //chicken
186
180
if (handItem .stackSize <= REFILL_THRESHOLD ) tryFillItemInHand (p );
187
- AxisAlignedBB box = AxisAlignedBB . fromBounds (p .posX - 2 , p .posY - 1 , p .posZ - 2 , p .posX + 2 , p .posY + 3 , p .posZ + 2 );
181
+ AxisAlignedBB box = new AxisAlignedBB (p .posX - 2 , p .posY - 1 , p .posZ - 2 , p .posX + 2 , p .posY + 3 , p .posZ + 2 );
188
182
if (tryFeedAnimal (EntityChicken .class , box , p )) return ;
189
183
} else if (handItem .getItem ().equals (Items .shears )) { // wool
190
- AxisAlignedBB box = AxisAlignedBB . fromBounds (p .posX - 2 , p .posY - 1 , p .posZ - 2 , p .posX + 2 , p .posY + 3 , p .posZ + 2 );
184
+ AxisAlignedBB box = new AxisAlignedBB (p .posX - 2 , p .posY - 1 , p .posZ - 2 , p .posX + 2 , p .posY + 3 , p .posZ + 2 );
191
185
for (EntitySheep e : (List <EntitySheep >) (p .getEntityWorld ().getEntitiesWithinAABB (EntitySheep .class , box ))) {
192
186
if (!e .isChild () && !e .getSheared ()) {
193
- FMLClientHandler .instance ().getClient ().playerController .interactWithEntitySendPacket (p , e );
187
+ FMLClientHandler .instance ().getClient ().playerController
188
+ .func_187097_a (p , e , p .getHeldItem (EnumHand .MAIN_HAND ), EnumHand .MAIN_HAND ); //interactWithEntity()
194
189
return ;
195
190
}
196
191
}
197
192
}
198
193
}
199
-
200
- private long gameTick = 0 ;
201
- private static final int ATTACK_GAP = 5 ;
202
- private Map <Entity , Long > attackTime = new HashMap <Entity , Long >();
203
-
204
- private void attackTick (EntityPlayer p ) {
205
- gameTick += tickRate ;
206
- AxisAlignedBB box = AxisAlignedBB .fromBounds (p .posX - 2 , p .posY - 2 , p .posZ - 2 , p .posX + 2 , p .posY + 3 , p .posZ + 2 );
207
- List <Entity > aroundMobs = p .getEntityWorld ().getEntitiesWithinAABB (EntityZombie .class , box );
208
- for (Entity e : aroundMobs ) {
209
- Long t = attackTime .get (e );
210
- if (t == null || t < gameTick ) {
211
- FMLClientHandler .instance ().getClient ().playerController .attackEntity (p , e );
212
- attackTime .put (e , gameTick );
213
- return ;
214
- }
215
- }
216
- }
217
-
218
- public void self_stop () {
219
- // CLEANUP
220
- FMLCommonHandler .instance ().bus ().unregister (this );
221
- }
222
194
}
0 commit comments