Новичок
- Статус
- Оффлайн
- Регистрация
- 28 Мар 2025
- Сообщения
- 1
- Реакции
- 0
Я у нейронки попросил сделать мне автофарм она вроде выдала че то годное
Java:
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber
public class AutoFarm {
private static boolean isRunning = false;
private static int tickCounter = 0;
private static BlockPos farmPos = null; // Позиция фермы (установите свою)
public static void toggle() {
isRunning = !isRunning;
if (isRunning) {
tickCounter = 0;
Minecraft.getInstance().player.sendChatMessage("Автоферма запущена!");
} else {
Minecraft.getInstance().player.sendChatMessage("Автоферма остановлена.");
}
}
@SubscribeEvent
public static void onClientTick(TickEvent.ClientTickEvent event) {
if (!isRunning || event.phase != TickEvent.Phase.END || Minecraft.getInstance().player == null) return;
tickCounter++;
if (tickCounter % 20 != 0) return; // Выполняем каждую секунду (20 тиков)
if (farmPos == null) {
// Установите позицию фермы перед использованием
farmPos = Minecraft.getInstance().player.getPosition();
return;
}
try {
// 1. Вспахиваем землю
hoeLand(farmPos);
// 2. Сажаем семена
plantSeeds(farmPos);
// 3. Используем костную муку
useBoneMeal(farmPos);
// 4. Собираем урожай
harvestCrops(farmPos);
} catch (Exception e) {
e.printStackTrace();
}
}
private static void hoeLand(BlockPos center) {
Minecraft mc = Minecraft.getInstance();
ItemStack hoe = findItemInHotbar(Items.DIAMOND_HOE); // Или другая мотыга
if (hoe.isEmpty()) return;
for (int x = -2; x <= 2; x++) {
for (int z = -2; z <= 2; z++) {
BlockPos pos = center.add(x, 0, z);
BlockState state = mc.world.getBlockState(pos);
if (state.getBlock() == Blocks.FARMLAND) continue;
if (state.getBlock() == Blocks.GRASS_BLOCK || state.getBlock() == Blocks.DIRT) {
// Переключаемся на мотыгу
int hoeSlot = mc.player.inventory.getSlotFor(hoe);
mc.player.inventory.currentItem = hoeSlot;
// Вспахиваем блок
mc.playerController.processRightClickBlock(mc.player, mc.world, pos,
net.minecraft.util.Direction.UP, Vector3d.ZERO, net.minecraft.util.Hand.MAIN_HAND);
}
}
}
}
private static void plantSeeds(BlockPos center) {
Minecraft mc = Minecraft.getInstance();
ItemStack seeds = findItemInHotbar(Items.CARROT); // Или Items.POTATO
if (seeds.isEmpty()) return;
for (int x = -2; x <= 2; x++) {
for (int z = -2; z <= 2; z++) {
BlockPos pos = center.add(x, 0, z).up();
BlockState state = mc.world.getBlockState(pos.down());
if (state.getBlock() == Blocks.FARMLAND && mc.world.isAirBlock(pos)) {
// Переключаемся на семена
int seedSlot = mc.player.inventory.getSlotFor(seeds);
mc.player.inventory.currentItem = seedSlot;
// Сажаем семена
mc.playerController.processRightClickBlock(mc.player, mc.world, pos.down(),
net.minecraft.util.Direction.UP, Vector3d.ZERO, net.minecraft.util.Hand.MAIN_HAND);
}
}
}
}
private static void useBoneMeal(BlockPos center) {
Minecraft mc = Minecraft.getInstance();
ItemStack boneMeal = findItemInHotbar(Items.BONE_MEAL);
if (boneMeal.isEmpty()) return;
for (int x = -2; x <= 2; x++) {
for (int z = -2; z <= 2; z++) {
BlockPos pos = center.add(x, 0, z).up();
BlockState state = mc.world.getBlockState(pos);
if (state.getBlock() == Items.CARROT.getBlock() || state.getBlock() == Items.POTATO.getBlock()) {
if (!isFullyGrown(state)) {
// Переключаемся на костную муку
int boneMealSlot = mc.player.inventory.getSlotFor(boneMeal);
mc.player.inventory.currentItem = boneMealSlot;
// Используем костную муку
mc.playerController.processRightClickBlock(mc.player, mc.world, pos,
net.minecraft.util.Direction.UP, Vector3d.ZERO, net.minecraft.util.Hand.MAIN_HAND);
}
}
}
}
}
private static void harvestCrops(BlockPos center) {
Minecraft mc = Minecraft.getInstance();
for (int x = -2; x <= 2; x++) {
for (int z = -2; z <= 2; z++) {
BlockPos pos = center.add(x, 0, z).up();
BlockState state = mc.world.getBlockState(pos);
if ((state.getBlock() == Items.CARROT.getBlock() || state.getBlock() == Items.POTATO.getBlock()) && isFullyGrown(state)) {
// Ломаем блок
mc.playerController.clickBlock(pos, net.minecraft.util.Direction.UP);
}
}
}
}
private static boolean isFullyGrown(BlockState state) {
return state.get(net.minecraft.block.CropsBlock.AGE) >= 7; // Максимальный возраст для моркови/картошки
}
private static ItemStack findItemInHotbar(net.minecraft.item.Item item) {
Minecraft mc = Minecraft.getInstance();
for (int i = 0; i < 9; i++) {
ItemStack stack = mc.player.inventory.getStackInSlot(i);
if (stack.getItem() == item) {
return stack;
}
}
return ItemStack.EMPTY;
}
}