diff --git a/src/main/java/com/flier268/autoharvest/AutoHarvest.java b/src/main/java/com/flier268/autoharvest/AutoHarvest.java index 243b397..eef9dc7 100644 --- a/src/main/java/com/flier268/autoharvest/AutoHarvest.java +++ b/src/main/java/com/flier268/autoharvest/AutoHarvest.java @@ -24,6 +24,7 @@ public enum HarvestMode { PLANT, // Plant only Farmer, //Harvest then re-plant SEED, // Harvest seeds & flowers + BONEMEALING, FEED, // Feed animals FISHING;// Fishing private static HarvestMode[] vals = values(); diff --git a/src/main/java/com/flier268/autoharvest/CropManager.java b/src/main/java/com/flier268/autoharvest/CropManager.java index f7ae0ae..11cb606 100644 --- a/src/main/java/com/flier268/autoharvest/CropManager.java +++ b/src/main/java/com/flier268/autoharvest/CropManager.java @@ -162,6 +162,11 @@ public static boolean isCropMature(World w, BlockPos pos, BlockState stat, Block return false; } + public static boolean isBoneMeal(ItemStack stack) { + return (!stack.isEmpty() + && stack.getItem() == Items.BONE_MEAL); + } + public static boolean isSeed(ItemStack stack) { return (!stack.isEmpty() && SEED_MAP.containsValue(stack.getItem())); diff --git a/src/main/java/com/flier268/autoharvest/KeyPressListener.java b/src/main/java/com/flier268/autoharvest/KeyPressListener.java index f0ca9ef..7361f20 100644 --- a/src/main/java/com/flier268/autoharvest/KeyPressListener.java +++ b/src/main/java/com/flier268/autoharvest/KeyPressListener.java @@ -12,7 +12,7 @@ public class KeyPressListener { private KeyBinding key_Switch, key_ModeChange, key_Config; - private KeyBinding key_HARVEST, key_PLANT, key_Farmer, key_SEED, key_FEED, key_FISHING; + private KeyBinding key_HARVEST, key_PLANT, key_Farmer, key_SEED, key_FEED, key_FISHING,Key_BONEMEALING; public KeyPressListener() { String categoryGeneral = new TranslatableText("key.category.general").getString(); @@ -54,6 +54,10 @@ public KeyPressListener() { GLFW.GLFW_KEY_UNKNOWN, categorySwitchTo ); + Key_BONEMEALING = new KeyBinding("bonemealing", + GLFW.GLFW_KEY_UNKNOWN, + categorySwitchTo + ); KeyBindingHelper.registerKeyBinding(key_ModeChange); KeyBindingHelper.registerKeyBinding(key_Switch); KeyBindingHelper.registerKeyBinding(key_Config); @@ -63,7 +67,7 @@ public KeyPressListener() { KeyBindingHelper.registerKeyBinding(key_SEED); KeyBindingHelper.registerKeyBinding(key_FEED); KeyBindingHelper.registerKeyBinding(key_FISHING); - + KeyBindingHelper.registerKeyBinding(Key_BONEMEALING); ClientTickEvents.END_CLIENT_TICK.register(client -> { onProcessKey(); @@ -92,6 +96,8 @@ public void onProcessKey() { modeName = AutoHarvest.instance.toSpecifiedMode(AutoHarvest.HarvestMode.FEED).toString().toLowerCase(); } else if (key_FISHING.wasPressed()) { modeName = AutoHarvest.instance.toSpecifiedMode(AutoHarvest.HarvestMode.FISHING).toString().toLowerCase(); + } else if (Key_BONEMEALING.wasPressed()) { + modeName = AutoHarvest.instance.toSpecifiedMode(AutoHarvest.HarvestMode.BONEMEALING).toString().toLowerCase(); } if (modeName != null) AutoHarvest.msg("notify.switch_to", new TranslatableText(modeName).getString()); diff --git a/src/main/java/com/flier268/autoharvest/TickListener.java b/src/main/java/com/flier268/autoharvest/TickListener.java index 70e8f70..7c4356c 100644 --- a/src/main/java/com/flier268/autoharvest/TickListener.java +++ b/src/main/java/com/flier268/autoharvest/TickListener.java @@ -4,6 +4,7 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; +import net.minecraft.block.CropBlock; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.entity.passive.AnimalEntity; @@ -77,6 +78,9 @@ public void onTick(ClientPlayerEntity player) { case FISHING: fishingTick(); break; + case BONEMEALING: + bonemealingTick(); + break; } } catch (Exception ex) { AutoHarvest.msg("notify.tick_error"); @@ -118,9 +122,9 @@ private void harvestTick() { if (CropManager.isCropMature(w, pos, state, b)) { if (b == Blocks.SWEET_BERRY_BUSH) { BlockPos downPos = pos.down(); - BlockHitResult blockHitResult = new BlockHitResult(new Vec3d(X + deltaX + 0.5, Y , Z + deltaZ + 0.5), Direction.UP, downPos, false); - ActionResult a= MinecraftClient.getInstance().interactionManager.interactBlock(p, MinecraftClient.getInstance().world, Hand.MAIN_HAND, blockHitResult); - String ass=""; + BlockHitResult blockHitResult = new BlockHitResult(new Vec3d(X + deltaX + 0.5, Y, Z + deltaZ + 0.5), Direction.UP, downPos, false); + ActionResult a = MinecraftClient.getInstance().interactionManager.interactBlock(p, MinecraftClient.getInstance().world, Hand.MAIN_HAND, blockHitResult); + String ass = ""; } else MinecraftClient.getInstance().interactionManager.attackBlock(pos, Direction.UP); return; @@ -289,7 +293,7 @@ private void feedTick() { } } if (handItem.getItem() == Items.SHEARS) { - for (SheepEntity e : p.getEntityWorld().getEntities(SheepEntity.class, box,null)) { + for (SheepEntity e : p.getEntityWorld().getEntities(SheepEntity.class, box, null)) { if (!e.isBaby() && !e.isSheared()) { lastUsedItem = handItem.copy(); MinecraftClient.getInstance().interactionManager.interactEntity(p, e, Hand.MAIN_HAND); @@ -341,4 +345,36 @@ private void fishingTick() { } } } + + /* clear all grass on land */ + private void bonemealingTick() { + ItemStack handItem = p.getMainHandStack(); + if (handItem == null || !CropManager.isBoneMeal(handItem)) { + return; + } else { + handItem = tryFillItemInHand(); + } + + World w = p.getEntityWorld(); + int X = (int) Math.floor(p.getX()); + int Y = (int) Math.floor(p.getY());//the "leg block" + int Z = (int) Math.floor(p.getZ()); + for (int deltaY = 3; deltaY >= -2; --deltaY) + for (int deltaX = -range; deltaX <= range; ++deltaX) + for (int deltaZ = -range; deltaZ <= range; ++deltaZ) { + BlockPos pos = new BlockPos(X + deltaX, Y + deltaY, Z + deltaZ); + BlockState blockState = w.getBlockState(pos); + Block block = blockState.getBlock(); + if (block instanceof CropBlock) { + //not Mature + if (!((CropBlock) block).isMature(blockState)) { + BlockHitResult blockHitResult = new BlockHitResult(new Vec3d(X + deltaX + 0.5, Y, Z + deltaZ + 0.5), Direction.UP, pos, false); + lastUsedItem = handItem.copy(); + ActionResult report = MinecraftClient.getInstance().interactionManager.interactBlock(MinecraftClient.getInstance().player, MinecraftClient.getInstance().world, Hand.MAIN_HAND, blockHitResult); + minusOneInHand(); + return; + } + } + } + } } diff --git a/src/main/resources/assets/autoharvest/lang/en_us.json b/src/main/resources/assets/autoharvest/lang/en_us.json index 2692c96..37dfc7d 100644 --- a/src/main/resources/assets/autoharvest/lang/en_us.json +++ b/src/main/resources/assets/autoharvest/lang/en_us.json @@ -12,6 +12,7 @@ "seed": "Seed mode", "feed": "Feed mode", "fishing": "Fishing mode", + "bonemealing": "bonemealing mode", "notify.switch_to":"Switch to: %s", "notify.lack_of_seed":"You need more seeds", "notify.prefix":"[AutoHarvest]", diff --git a/src/main/resources/assets/autoharvest/lang/zh_cn.json b/src/main/resources/assets/autoharvest/lang/zh_cn.json index 62551f0..f7639fd 100644 --- a/src/main/resources/assets/autoharvest/lang/zh_cn.json +++ b/src/main/resources/assets/autoharvest/lang/zh_cn.json @@ -12,6 +12,7 @@ "seed": "除草 模式", "feed": "喂食 模式", "fishing": "钓鱼 模式", + "bonemealing": "催熟 模式", "notify.switch_to":"已切换到 %s", "notify.lack_of_seed":"缺少种子", "notify.prefix":"[自动收割]", diff --git a/src/main/resources/assets/autoharvest/lang/zh_tw.json b/src/main/resources/assets/autoharvest/lang/zh_tw.json index 5803d8b..4f89c12 100644 --- a/src/main/resources/assets/autoharvest/lang/zh_tw.json +++ b/src/main/resources/assets/autoharvest/lang/zh_tw.json @@ -12,6 +12,7 @@ "seed": "除草 模式", "feed": "餵食 模式", "fishing": "釣魚 模式", + "bonemealing": "催熟 模式", "notify.switch_to":"已切換到 %s", "notify.lack_of_seed":"缺少種子", "notify.prefix":"[自動收割]",