Skip to content
This repository was archived by the owner on Jan 3, 2020. It is now read-only.

Commit b9283d5

Browse files
committed
update to mc1.9-forge1891
1 parent 9510642 commit b9283d5

File tree

7 files changed

+46
-74
lines changed

7 files changed

+46
-74
lines changed

build.gradle

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
// For those who want the bleeding edge
13
buildscript {
24
repositories {
35
jcenter()
@@ -7,19 +9,22 @@ buildscript {
79
}
810
}
911
dependencies {
10-
classpath 'net.minecraftforge.gradle:ForgeGradle:2.0-SNAPSHOT'
12+
classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT'
1113
}
1214
}
1315
apply plugin: 'net.minecraftforge.gradle.forge'
1416

15-
version = "2.0"
17+
sourceCompatibility = 1.7
18+
targetCompatibility = 1.7
19+
20+
version = "2.1"
1621
group= "org.devinprogress.autoharvest"
17-
archivesBaseName = "AutoHarvest-1.8"
22+
archivesBaseName = "AutoHarvest-mc1.9-forge1891"
1823

1924
minecraft {
20-
version = "1.8-11.14.4.1563"
25+
version = "1.9-12.16.1.1891"
2126
runDir = "../gameDir"
22-
mappings = "stable_18"
27+
mappings = "snapshot_20160312"
2328
}
2429

2530
dependencies { }

src/main/java/org/devinprogress/autoharvest/AutoHarvest.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.devinprogress.autoharvest;
22

33
import net.minecraft.client.resources.I18n;
4-
import net.minecraft.util.ChatComponentText;
4+
import net.minecraft.util.text.TextComponentString;
5+
import net.minecraftforge.common.MinecraftForge;
56
import net.minecraftforge.fml.client.FMLClientHandler;
6-
import net.minecraftforge.fml.common.FMLCommonHandler;
77
import net.minecraftforge.fml.common.Mod;
88
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
99
import net.minecraftforge.fml.relauncher.Side;
@@ -13,12 +13,11 @@
1313
@SideOnly(Side.CLIENT)
1414
public class AutoHarvest {
1515
public enum HarvestMode {
16-
//SMART, // Harvest then re-plant
16+
SMART, // Harvest then re-plant
1717
EAGER, // Harvest only
1818
PLANT, // Plant only
1919
SEED, // Harvest seeds & flowers
2020
FEED, // Feed animals
21-
//ATTACK, // Attack zombies
2221
OFF; // Turn off mod
2322
private static HarvestMode[] vals = values();
2423

@@ -34,19 +33,19 @@ public AutoHarvest.HarvestMode next() {
3433

3534
@Mod.EventHandler
3635
public void preInit(FMLPreInitializationEvent event) {
37-
FMLCommonHandler.instance().bus().register(new KeyPressListener());
36+
MinecraftForge.EVENT_BUS.register(new KeyPressListener());
3837
}
3938

4039
private void setEnabled() {
4140
if (listener == null) {
4241
listener = new TickListener(mode);
43-
FMLCommonHandler.instance().bus().register(listener);
42+
MinecraftForge.EVENT_BUS.register(listener);
4443
}
4544
}
4645

4746
private void setDisabled() {
4847
if (listener != null) {
49-
listener.self_stop();
48+
MinecraftForge.EVENT_BUS.unregister(listener);
5049
listener = null;
5150
}
5251
}
@@ -68,15 +67,10 @@ public void toNextMode(HarvestMode nextMode) {
6867
}
6968
}
7069

71-
private static void sendMessage(String msg) {
72-
FMLClientHandler.instance().getClient().thePlayer.addChatMessage(new ChatComponentText(msg));
73-
}
74-
75-
public static void sendI18nMsg(String id) {
76-
sendMessage(i18n(id));
77-
}
78-
79-
private static String i18n(String key) {
80-
return I18n.format(key);
70+
public static void msg(String key, Object... obj) {
71+
FMLClientHandler.instance().getClient().thePlayer.addChatMessage(new TextComponentString(
72+
I18n.format("notify.prefix")
73+
+ I18n.format(key, obj)
74+
));
8175
}
8276
}

src/main/java/org/devinprogress/autoharvest/CropManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import net.minecraft.init.Items;
77
import net.minecraft.item.Item;
88
import net.minecraft.item.ItemStack;
9-
import net.minecraft.util.BlockPos;
9+
import net.minecraft.util.math.BlockPos;
1010
import net.minecraft.world.World;
1111

1212
import java.util.HashMap;
@@ -29,7 +29,6 @@ public class CropManager {
2929
add(Block.getBlockFromName("brown_mushroom"));
3030
add(Block.getBlockFromName("red_mushroom"));
3131
add(Block.getBlockFromName("double_plant"));
32-
add(Blocks.fire);
3332
}};
3433

3534
public static final Map<Block, Item> CROP_BLOCKS = new HashMap<Block, Item>() {{

src/main/java/org/devinprogress/autoharvest/KeyPressListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public void onKeyPressed(InputEvent.KeyInputEvent event) {
1818
if (toggleKey.isPressed()) {
1919
AutoHarvest a = AutoHarvest.instance;
2020
String modeName = a.toNextMode().toString().toLowerCase();
21-
AutoHarvest.sendI18nMsg("notify.switch_to." + modeName);
21+
AutoHarvest.msg("notify.switch_to." + modeName);
2222
}
2323
}
2424
}

src/main/java/org/devinprogress/autoharvest/TickListener.java

Lines changed: 21 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,25 @@
33
import net.minecraft.block.Block;
44
import net.minecraft.block.state.IBlockState;
55
import net.minecraft.client.Minecraft;
6-
import net.minecraft.entity.Entity;
7-
import net.minecraft.entity.monster.EntityZombie;
86
import net.minecraft.entity.passive.*;
97
import net.minecraft.entity.player.EntityPlayer;
108
import net.minecraft.entity.player.InventoryPlayer;
119
import net.minecraft.init.Blocks;
1210
import net.minecraft.init.Items;
1311
import net.minecraft.item.Item;
1412
import net.minecraft.item.ItemStack;
15-
import net.minecraft.util.AxisAlignedBB;
16-
import net.minecraft.util.BlockPos;
1713
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;
1918
import net.minecraft.world.World;
2019
import net.minecraftforge.fml.client.FMLClientHandler;
21-
import net.minecraftforge.fml.common.FMLCommonHandler;
2220
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
2321
import net.minecraftforge.fml.common.gameevent.TickEvent;
2422
import net.minecraftforge.fml.relauncher.Side;
2523

26-
import java.util.HashMap;
2724
import java.util.List;
28-
import java.util.Map;
2925

3026
public class TickListener {
3127
private int tickCount = 0;
@@ -38,7 +34,6 @@ public TickListener(AutoHarvest.HarvestMode mode) {
3834
this.mode = mode;
3935
}
4036

41-
@SuppressWarnings("unused")
4237
@SubscribeEvent
4338
public void onTick(TickEvent.PlayerTickEvent e) {
4439
if (e.side == Side.CLIENT && e.player != null &&
@@ -62,10 +57,6 @@ public void onTick(TickEvent.PlayerTickEvent e) {
6257
feedTick(e.player);
6358
break;
6459
}
65-
// case ATTACK: {
66-
// attackTick(e.player);
67-
// break;
68-
// }
6960
}
7061
}
7162
}
@@ -121,15 +112,15 @@ private boolean tryFillItemInHand(EntityPlayer p) {
121112
return true;
122113
}
123114
}
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");
126117
AutoHarvest.instance.toNextMode(AutoHarvest.HarvestMode.OFF);
127118

128119
return false;
129120
}
130121

131122
private void plantTick(EntityPlayer p) {
132-
ItemStack handItem = p.getHeldItem();
123+
ItemStack handItem = p.getHeldItem(EnumHand.MAIN_HAND);
133124
if (!CropManager.isSeed(handItem)) {
134125
return;
135126
}
@@ -148,75 +139,56 @@ private void plantTick(EntityPlayer p) {
148139
&& downBlock != Blocks.air
149140
&& CropManager.canPlantOn(handItem.getItem(), w, downPos, downBlock)) {
150141
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(
153145
FMLClientHandler.instance().getClientPlayerEntity(),
154146
FMLClientHandler.instance().getWorldClient(),
155147
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);
157150
}
158151
}
159152
}
160153

161154
private boolean tryFeedAnimal(Class<? extends EntityAnimal> type, AxisAlignedBB box, EntityPlayer p) {
162155
for (EntityAnimal e : (List<EntityAnimal>) (p.getEntityWorld().getEntitiesWithinAABB(type, box))) {
163156
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()
165159
return true;
166160
}
167161
}
168162
return false;
169163
}
170164

171165
private void feedTick(EntityPlayer p) {
172-
ItemStack handItem = p.getHeldItem();
166+
ItemStack handItem = p.getHeldItem(EnumHand.MAIN_HAND);
173167
if (handItem == null) return;
174168
if (handItem.getItem().equals(Items.carrot)) { //pig & rabbit
175169
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);
177171
if (tryFeedAnimal(EntityPig.class, box, p)) return;
178172
if (tryFeedAnimal(EntityRabbit.class, box, p)) return;
179173
} else if (handItem.getItem().equals(Items.wheat)) { //cow & sheep & mooshrom
180174
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);
182176
if (tryFeedAnimal(EntityCow.class, box, p)) return;
183177
if (tryFeedAnimal(EntityMooshroom.class, box, p)) return;
184178
if (tryFeedAnimal(EntitySheep.class, box, p)) return;
185179
} else if (handItem.getItem().equals(Items.wheat_seeds)) { //chicken
186180
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);
188182
if (tryFeedAnimal(EntityChicken.class, box, p)) return;
189183
} 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);
191185
for (EntitySheep e : (List<EntitySheep>) (p.getEntityWorld().getEntitiesWithinAABB(EntitySheep.class, box))) {
192186
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()
194189
return;
195190
}
196191
}
197192
}
198193
}
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-
}
222194
}

src/main/resources/assets/autoharvest/lang/en_US.lang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ notify.switch_to.feed=Switch to: Feed
77
notify.switch_to.attack=Switch to: Attack
88
notify.switch_to.off=AutoHarvest turned off
99
notify.lack_of_seed=You need more seeds
10+
notify.prefix=[AutoHarvest]

src/main/resources/assets/autoharvest/lang/zh_CN.lang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ notify.switch_to.feed=已切换到 喂食 模式
77
notify.switch_to.attack=已切换到 攻击 模式
88
notify.switch_to.off=自动收割 已关闭
99
notify.lack_of_seed=缺少种子
10+
notify.prefix=[自动收割]

0 commit comments

Comments
 (0)