Search in sources :

Example 1 with HoeItem

use of net.minecraft.item.HoeItem in project BleachHack by BleachDrinker420.

the class AutoFarm method onTick.

@BleachSubscribe
public void onTick(EventTick event) {
    mossMap.entrySet().removeIf(e -> e.setValue(e.getValue() - 1) == 0);
    double range = getSetting(0).asSlider().getValue();
    int ceilRange = MathHelper.ceil(range);
    SettingToggle tillSetting = getSetting(1).asToggle();
    SettingToggle harvestSetting = getSetting(2).asToggle();
    SettingToggle plantSetting = getSetting(3).asToggle();
    SettingToggle bonemealSetting = getSetting(4).asToggle();
    // Special case for moss to maximize efficiency
    if (bonemealSetting.getState() && bonemealSetting.getChild(6).asToggle().getState()) {
        int slot = InventoryUtils.getSlot(true, i -> mc.player.getInventory().getStack(i).getItem() == Items.BONE_MEAL);
        if (slot != -1) {
            BlockPos bestBlock = BlockPos.streamOutwards(new BlockPos(mc.player.getEyePos()), ceilRange, ceilRange, ceilRange).filter(b -> mc.player.getEyePos().distanceTo(Vec3d.ofCenter(b)) <= range && !mossMap.containsKey(b)).map(b -> Pair.of(b.toImmutable(), getMossSpots(b))).filter(p -> p.getRight() > 10).map(Pair::getLeft).min(Comparator.reverseOrder()).orElse(null);
            if (bestBlock != null) {
                if (!mc.world.isAir(bestBlock.up())) {
                    mc.interactionManager.updateBlockBreakingProgress(bestBlock.up(), Direction.UP);
                }
                Hand hand = InventoryUtils.selectSlot(slot);
                mc.interactionManager.interactBlock(mc.player, mc.world, hand, new BlockHitResult(Vec3d.ofCenter(bestBlock, 1), Direction.UP, bestBlock, false));
                mossMap.put(bestBlock, 100);
                return;
            }
        }
    }
    for (BlockPos pos : BlockPos.iterateOutwards(new BlockPos(mc.player.getEyePos()), ceilRange, ceilRange, ceilRange)) {
        if (mc.player.getEyePos().distanceTo(Vec3d.ofCenter(pos)) > range)
            continue;
        BlockState state = mc.world.getBlockState(pos);
        Block block = state.getBlock();
        if (tillSetting.getState() && canTill(block) && mc.world.isAir(pos.up())) {
            if (!tillSetting.getChild(0).asToggle().getState() || BlockPos.stream(pos.getX() - 4, pos.getY(), pos.getZ() - 4, pos.getX() + 4, pos.getY(), pos.getZ() + 4).anyMatch(b -> mc.world.getFluidState(b).isIn(FluidTags.WATER))) {
                Hand hand = InventoryUtils.selectSlot(true, i -> mc.player.getInventory().getStack(i).getItem() instanceof HoeItem);
                if (hand != null) {
                    mc.interactionManager.interactBlock(mc.player, mc.world, hand, new BlockHitResult(Vec3d.ofCenter(pos, 1), Direction.UP, pos, false));
                    return;
                }
            }
        }
        if (harvestSetting.getState()) {
            if ((harvestSetting.getChild(0).asToggle().getState() && block instanceof CropBlock && ((CropBlock) block).isMature(state)) || (harvestSetting.getChild(1).asToggle().getState() && block instanceof GourdBlock) || (harvestSetting.getChild(2).asToggle().getState() && block instanceof NetherWartBlock && state.get(NetherWartBlock.AGE) >= 3) || (harvestSetting.getChild(3).asToggle().getState() && block instanceof CocoaBlock && state.get(CocoaBlock.AGE) >= 2) || (harvestSetting.getChild(4).asToggle().getState() && block instanceof SweetBerryBushBlock && state.get(SweetBerryBushBlock.AGE) >= 3) || (harvestSetting.getChild(5).asToggle().getState() && shouldHarvestTallCrop(pos, block, SugarCaneBlock.class)) || (harvestSetting.getChild(6).asToggle().getState() && shouldHarvestTallCrop(pos, block, CactusBlock.class))) {
                mc.interactionManager.updateBlockBreakingProgress(pos, Direction.UP);
                return;
            }
        }
        if (plantSetting.getState() && mc.world.getOtherEntities(null, new Box(pos.up()), EntityPredicates.VALID_LIVING_ENTITY).isEmpty()) {
            if (block instanceof FarmlandBlock && mc.world.isAir(pos.up())) {
                int slot = InventoryUtils.getSlot(true, i -> {
                    Item item = mc.player.getInventory().getStack(i).getItem();
                    if (plantSetting.getChild(0).asToggle().getState() && (item == Items.WHEAT_SEEDS || item == Items.CARROT || item == Items.POTATO || item == Items.BEETROOT_SEEDS)) {
                        return true;
                    }
                    return plantSetting.getChild(1).asToggle().getState() && (item == Items.PUMPKIN_SEEDS || item == Items.MELON_SEEDS);
                });
                if (slot != -1) {
                    WorldUtils.placeBlock(pos.up(), slot, 0, false, false, true);
                    return;
                }
            }
            if (block instanceof SoulSandBlock && mc.world.isAir(pos.up()) && plantSetting.getChild(2).asToggle().getState()) {
                int slot = InventoryUtils.getSlot(true, i -> mc.player.getInventory().getStack(i).getItem() == Items.NETHER_WART);
                if (slot != -1) {
                    WorldUtils.placeBlock(pos.up(), slot, 0, false, false, true);
                    return;
                }
            }
        }
        if (bonemealSetting.getState()) {
            int slot = InventoryUtils.getSlot(true, i -> mc.player.getInventory().getStack(i).getItem() == Items.BONE_MEAL);
            if (slot != -1) {
                if ((bonemealSetting.getChild(0).asToggle().getState() && block instanceof CropBlock && !((CropBlock) block).isMature(state)) || (bonemealSetting.getChild(1).asToggle().getState() && block instanceof StemBlock && state.get(StemBlock.AGE) < StemBlock.MAX_AGE) || (bonemealSetting.getChild(2).asToggle().getState() && block instanceof CocoaBlock && state.get(CocoaBlock.AGE) < 2) || (bonemealSetting.getChild(3).asToggle().getState() && block instanceof SweetBerryBushBlock && state.get(SweetBerryBushBlock.AGE) < 3) || (bonemealSetting.getChild(4).asToggle().getState() && block instanceof MushroomPlantBlock) || (bonemealSetting.getChild(5).asToggle().getState() && (block instanceof SaplingBlock || block instanceof AzaleaBlock) && canPlaceSapling(pos))) {
                    Hand hand = InventoryUtils.selectSlot(slot);
                    mc.interactionManager.interactBlock(mc.player, mc.world, hand, new BlockHitResult(Vec3d.ofCenter(pos, 1), Direction.UP, pos, false));
                    return;
                }
            }
        }
    }
}
Also used : BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe) SettingSlider(org.bleachhack.setting.module.SettingSlider) ModuleCategory(org.bleachhack.module.ModuleCategory) Item(net.minecraft.item.Item) net.minecraft.util.math(net.minecraft.util.math) BlockHitResult(net.minecraft.util.hit.BlockHitResult) InventoryUtils(org.bleachhack.util.InventoryUtils) HashMap(java.util.HashMap) Items(net.minecraft.item.Items) Module(org.bleachhack.module.Module) FluidTags(net.minecraft.tag.FluidTags) WorldUtils(org.bleachhack.util.world.WorldUtils) Pair(org.apache.commons.lang3.tuple.Pair) net.minecraft.block(net.minecraft.block) EntityPredicates(net.minecraft.predicate.entity.EntityPredicates) TreeFeature(net.minecraft.world.gen.feature.TreeFeature) Map(java.util.Map) Hand(net.minecraft.util.Hand) SettingToggle(org.bleachhack.setting.module.SettingToggle) Comparator(java.util.Comparator) EventTick(org.bleachhack.event.events.EventTick) HoeItem(net.minecraft.item.HoeItem) HoeItem(net.minecraft.item.HoeItem) Item(net.minecraft.item.Item) HoeItem(net.minecraft.item.HoeItem) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Pair(org.apache.commons.lang3.tuple.Pair) Hand(net.minecraft.util.Hand) SettingToggle(org.bleachhack.setting.module.SettingToggle) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 2 with HoeItem

use of net.minecraft.item.HoeItem in project Wurst7 by Wurst-Imperium.

the class TillauraHack method onUpdate.

@Override
public void onUpdate() {
    // wait for right click timer
    if (IMC.getItemUseCooldown() > 0)
        return;
    // check held item
    ItemStack stack = MC.player.getInventory().getMainHandStack();
    if (stack.isEmpty() || !(stack.getItem() instanceof HoeItem))
        return;
    // get valid blocks
    ArrayList<BlockPos> validBlocks = getValidBlocks(range.getValue(), this::isCorrectBlock);
    if (multiTill.isChecked()) {
        boolean shouldSwing = false;
        // till all valid blocks
        for (BlockPos pos : validBlocks) if (rightClickBlockSimple(pos))
            shouldSwing = true;
        // swing arm
        if (shouldSwing)
            MC.player.swingHand(Hand.MAIN_HAND);
    } else
        // till next valid block
        for (BlockPos pos : validBlocks) if (rightClickBlockLegit(pos))
            break;
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) HoeItem(net.minecraft.item.HoeItem)

Example 3 with HoeItem

use of net.minecraft.item.HoeItem in project LevelZ by Globox1997.

the class LevelzGui method getDamageLabel.

private String getDamageLabel(PlayerStatsManager playerStatsManager, PlayerEntity playerEntity) {
    float damage = 0.0F;
    boolean isSword = false;
    Item item = playerEntity.getMainHandStack().getItem();
    if (item instanceof ToolItem) {
        ArrayList<Object> levelList = new ArrayList<Object>();
        if (item instanceof SwordItem) {
            levelList = LevelLists.swordList;
            isSword = true;
        } else if (item instanceof AxeItem)
            levelList = LevelLists.axeList;
        else if (item instanceof HoeItem)
            levelList = LevelLists.hoeList;
        else
            levelList = LevelLists.toolList;
        if (PlayerStatsManager.playerLevelisHighEnough(playerEntity, levelList, ((ToolItem) item).getMaterial().toString().toLowerCase(), false)) {
            if (isSword)
                damage = ((SwordItem) item).getAttackDamage();
            else if (item instanceof MiningToolItem)
                damage = ((MiningToolItem) item).getAttackDamage();
        }
    }
    damage += playerEntity.getAttributeValue(EntityAttributes.GENERIC_ATTACK_DAMAGE);
    return "" + BigDecimal.valueOf(damage).setScale(2, RoundingMode.HALF_DOWN).floatValue();
}
Also used : Item(net.minecraft.item.Item) MiningToolItem(net.minecraft.item.MiningToolItem) SwordItem(net.minecraft.item.SwordItem) AxeItem(net.minecraft.item.AxeItem) ToolItem(net.minecraft.item.ToolItem) HoeItem(net.minecraft.item.HoeItem) ArrayList(java.util.ArrayList) MiningToolItem(net.minecraft.item.MiningToolItem) SwordItem(net.minecraft.item.SwordItem) AxeItem(net.minecraft.item.AxeItem) HoeItem(net.minecraft.item.HoeItem) MiningToolItem(net.minecraft.item.MiningToolItem) ToolItem(net.minecraft.item.ToolItem)

Example 4 with HoeItem

use of net.minecraft.item.HoeItem in project carpet-extra by gnembon.

the class CarpetExtraDispenserBehaviors method getCustomDispenserBehavior.

// get custom dispenser behavior
// this checks conditions such as the item and certain block or entity being in front of the dispenser to decide which rule to return
// if the conditions for the rule match, it returns the instance of the dispenser behavior
// returns null to fallback to vanilla (or another mod's) behavior for the given item
public static DispenserBehavior getCustomDispenserBehavior(ServerWorld world, BlockPos pos, BlockPointer pointer, DispenserBlockEntity dispenserBlockEntity, ItemStack stack, Map<Item, DispenserBehavior> VANILLA_BEHAVIORS) {
    Item item = stack.getItem();
    Direction dispenserFacing = pointer.getBlockState().get(DispenserBlock.FACING);
    BlockPos frontBlockPos = pos.offset(dispenserFacing);
    BlockState frontBlockState = world.getBlockState(frontBlockPos);
    Block frontBlock = frontBlockState.getBlock();
    Box frontBlockBox = new Box(frontBlockPos);
    // blazeMeal
    if (CarpetExtraSettings.blazeMeal && item == Items.BLAZE_POWDER && frontBlock == Blocks.NETHER_WART) {
        return BLAZE_MEAL;
    }
    // chickenShearing
    if (CarpetExtraSettings.chickenShearing && item == Items.SHEARS) {
        boolean hasShearableChickens = !world.getEntitiesByType(EntityType.CHICKEN, frontBlockBox, EntityPredicates.VALID_LIVING_ENTITY.and((chickenEntity) -> {
            return !((AnimalEntity) chickenEntity).isBaby();
        })).isEmpty();
        if (hasShearableChickens) {
            return SHEAR_CHICKEN;
        }
    }
    // dispensersCarvePumpkins
    if (CarpetExtraSettings.dispensersCarvePumpkins && item instanceof ShearsItem && frontBlock == Blocks.PUMPKIN) {
        return CARVE_PUMPKIN;
    }
    // dispensersFeedAnimals
    if (CarpetExtraSettings.dispensersFeedAnimals) {
        // check for animals that can be bred with the current item being dispensed in front of dispenser
        boolean hasFeedableAnimals = !world.getEntitiesByClass(AnimalEntity.class, frontBlockBox, EntityPredicates.VALID_LIVING_ENTITY.and((animalEntity) -> {
            return ((AnimalEntity) animalEntity).isBreedingItem(stack);
        })).isEmpty();
        if (hasFeedableAnimals) {
            return FEED_ANIMAL;
        }
        // get brown mooshrooms in front of dispenser
        boolean hasFeedableMooshrooms = !world.getEntitiesByType(EntityType.MOOSHROOM, frontBlockBox, EntityPredicates.VALID_LIVING_ENTITY.and((mooshroomEntity) -> {
            return ((MooshroomEntity) mooshroomEntity).getMooshroomType() == MooshroomEntity.Type.BROWN;
        })).isEmpty();
        // check if item is a small flower
        if (hasFeedableMooshrooms && item.getRegistryEntry().isIn(ItemTags.SMALL_FLOWERS)) {
            return FEED_MOOSHROOM;
        }
    }
    // dispensersFillMinecarts
    if (CarpetExtraSettings.dispensersFillMinecarts) {
        // check for minecarts with no riders in front of dispenser
        boolean hasMinecarts = !world.getEntitiesByType(EntityType.MINECART, frontBlockBox, EntityPredicates.NOT_MOUNTED).isEmpty();
        // if a minecart exist, return dispenser behavior according to item type
        if (hasMinecarts) {
            if (item == Items.CHEST) {
                return FILL_MINECART_CHEST;
            } else if (item == Items.FURNACE) {
                return FILL_MINECART_FURNACE;
            } else if (item == Items.TNT) {
                return FILL_MINECART_TNT;
            } else if (item == Items.HOPPER) {
                return FILL_MINECART_HOPPER;
            }
        }
    }
    // dispensersMilkAnimals
    if (CarpetExtraSettings.dispensersMilkAnimals) {
        // bucket to milk
        if (item == Items.BUCKET) {
            // check for cows, mooshrooms, or goats in front of dispenser
            boolean hasMilkable = !world.getEntitiesByClass(AnimalEntity.class, frontBlockBox, EntityPredicates.VALID_LIVING_ENTITY.and((animalEntity) -> {
                return animalEntity instanceof CowEntity || animalEntity instanceof GoatEntity;
            })).isEmpty();
            if (hasMilkable) {
                return MILK_ANIMAL;
            }
        } else // bowl to stew
        if (item == Items.BOWL) {
            // check for mooshrooms in front of dispenser
            boolean hasMooshroom = !world.getEntitiesByType(EntityType.MOOSHROOM, frontBlockBox, EntityPredicates.VALID_LIVING_ENTITY).isEmpty();
            if (hasMooshroom) {
                return MILK_MOOSHROOM;
            }
        }
    }
    // dispensersPlayRecords
    if (CarpetExtraSettings.dispensersPlayRecords && item instanceof MusicDiscItem && frontBlock == Blocks.JUKEBOX) {
        return PLAY_DISC;
    }
    // dispensersPotPlants
    if (CarpetExtraSettings.dispensersPotPlants && frontBlock instanceof FlowerPotBlock && FlowerPotHelper.isPottable(item)) {
        return FILL_FLOWER_POT;
    }
    // dispensersStripBlocks
    if (CarpetExtraSettings.dispensersStripBlocks && item instanceof AxeItem && (StripBlocksDispenserBehavior.canStrip(frontBlock) || StripBlocksDispenserBehavior.isStripResult(frontBlock))) {
        return STRIP_BLOCK;
    }
    // dispensersTillSoil
    if (CarpetExtraSettings.dispensersTillSoil && item instanceof HoeItem) {
        // check block in front of dispenser and one block down
        for (int i = 0; i < 2; i++) {
            BlockPos hoeBlockPos = frontBlockPos.down(i);
            Block hoeBlock = world.getBlockState(hoeBlockPos).getBlock();
            // check if block is in tilled blocks, or is farmland (to prevent hoe being dispensed when you don't want it to)
            if (TillSoilDispenserBehavior.TILLED_BLOCKS.contains(hoeBlock) || hoeBlock == Blocks.FARMLAND) {
                return TILL_SOIL;
            }
        }
    }
    // dispensersToggleThings
    if (CarpetExtraSettings.dispensersToggleThings && item == Items.STICK && ToggleBlockDispenserBehavior.TOGGLEABLE_BLOCKS.contains(frontBlock)) {
        return TOGGLE_BLOCK;
    }
    // dispensersUseCauldrons
    if (CarpetExtraSettings.dispensersUseCauldrons && frontBlock instanceof AbstractCauldronBlock) {
        // empty cauldron
        if (item == Items.BUCKET) {
            return CAULDRON_EMPTYING_BUCKET;
        } else // fill cauldron
        if (item == Items.LAVA_BUCKET || item == Items.WATER_BUCKET || item == Items.POWDER_SNOW_BUCKET) {
            return CAULDRON_FILLING_BUCKET;
        } else // water cauldron behaviors (leather armor, shulker boxes, banners)
        if (CauldronWaterDispenserBehavior.isWaterCauldronItem(stack)) {
            return CAULDRON_WATER;
        }
    }
    // renewableEndstone
    if (CarpetExtraSettings.renewableEndstone && item == Items.DRAGON_BREATH && frontBlock == Blocks.COBBLESTONE) {
        return DRAGON_BREATH_ENDSTONE;
    }
    // renewableNetherrack
    if (CarpetExtraSettings.renewableNetherrack && item == Items.FIRE_CHARGE && frontBlock == Blocks.COBBLESTONE) {
        return FIRE_CHARGE_NETHERRACK;
    }
    // no custom behavior, return null
    return null;
}
Also used : EntityType(net.minecraft.entity.EntityType) ItemTags(net.minecraft.tag.ItemTags) TillSoilDispenserBehavior(carpetextra.dispenser.behaviors.TillSoilDispenserBehavior) CauldronFillingDispenserBehavior(carpetextra.dispenser.behaviors.CauldronFillingDispenserBehavior) FlowerPotBlock(net.minecraft.block.FlowerPotBlock) Item(net.minecraft.item.Item) BlockPointer(net.minecraft.util.math.BlockPointer) CarvePumpkinDispenserBehavior(carpetextra.dispenser.behaviors.CarvePumpkinDispenserBehavior) GoatEntity(net.minecraft.entity.passive.GoatEntity) MooshroomEntity(net.minecraft.entity.passive.MooshroomEntity) FillMinecartDispenserBehavior(carpetextra.dispenser.behaviors.FillMinecartDispenserBehavior) Block(net.minecraft.block.Block) MusicDiscDispenserBehavior(carpetextra.dispenser.behaviors.MusicDiscDispenserBehavior) Map(java.util.Map) DragonBreathDispenserBehavior(carpetextra.dispenser.behaviors.DragonBreathDispenserBehavior) BlockState(net.minecraft.block.BlockState) CauldronEmptyingDispenserBehavior(carpetextra.dispenser.behaviors.CauldronEmptyingDispenserBehavior) DispenserBlockEntity(net.minecraft.block.entity.DispenserBlockEntity) AxeItem(net.minecraft.item.AxeItem) FireChargeDispenserBehavior(carpetextra.dispenser.behaviors.FireChargeDispenserBehavior) DispenserBehavior(net.minecraft.block.dispenser.DispenserBehavior) StripBlocksDispenserBehavior(carpetextra.dispenser.behaviors.StripBlocksDispenserBehavior) CauldronWaterDispenserBehavior(carpetextra.dispenser.behaviors.CauldronWaterDispenserBehavior) CarpetExtraSettings(carpetextra.CarpetExtraSettings) HoeItem(net.minecraft.item.HoeItem) ServerWorld(net.minecraft.server.world.ServerWorld) CowEntity(net.minecraft.entity.passive.CowEntity) Direction(net.minecraft.util.math.Direction) ItemStack(net.minecraft.item.ItemStack) AbstractMinecartEntity(net.minecraft.entity.vehicle.AbstractMinecartEntity) EntityPredicates(net.minecraft.predicate.entity.EntityPredicates) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) MilkMooshroomDispenserBehavior(carpetextra.dispenser.behaviors.MilkMooshroomDispenserBehavior) MusicDiscItem(net.minecraft.item.MusicDiscItem) ShearsItem(net.minecraft.item.ShearsItem) ToggleBlockDispenserBehavior(carpetextra.dispenser.behaviors.ToggleBlockDispenserBehavior) Box(net.minecraft.util.math.Box) MilkAnimalDispenserBehavior(carpetextra.dispenser.behaviors.MilkAnimalDispenserBehavior) BlockPos(net.minecraft.util.math.BlockPos) FlowerPotDispenserBehavior(carpetextra.dispenser.behaviors.FlowerPotDispenserBehavior) Items(net.minecraft.item.Items) AbstractCauldronBlock(net.minecraft.block.AbstractCauldronBlock) Blocks(net.minecraft.block.Blocks) FeedAnimalDispenserBehavior(carpetextra.dispenser.behaviors.FeedAnimalDispenserBehavior) FeedMooshroomDispenserBehavior(carpetextra.dispenser.behaviors.FeedMooshroomDispenserBehavior) ShearChickenDispenserBehavior(carpetextra.dispenser.behaviors.ShearChickenDispenserBehavior) FlowerPotHelper(carpetextra.helpers.FlowerPotHelper) DispenserBlock(net.minecraft.block.DispenserBlock) BlazePowderDispenserBehavior(carpetextra.dispenser.behaviors.BlazePowderDispenserBehavior) AbstractCauldronBlock(net.minecraft.block.AbstractCauldronBlock) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) Box(net.minecraft.util.math.Box) ShearsItem(net.minecraft.item.ShearsItem) GoatEntity(net.minecraft.entity.passive.GoatEntity) Direction(net.minecraft.util.math.Direction) AxeItem(net.minecraft.item.AxeItem) HoeItem(net.minecraft.item.HoeItem) MusicDiscItem(net.minecraft.item.MusicDiscItem) Item(net.minecraft.item.Item) AxeItem(net.minecraft.item.AxeItem) HoeItem(net.minecraft.item.HoeItem) MusicDiscItem(net.minecraft.item.MusicDiscItem) ShearsItem(net.minecraft.item.ShearsItem) BlockState(net.minecraft.block.BlockState) FlowerPotBlock(net.minecraft.block.FlowerPotBlock) Block(net.minecraft.block.Block) AbstractCauldronBlock(net.minecraft.block.AbstractCauldronBlock) DispenserBlock(net.minecraft.block.DispenserBlock) BlockPos(net.minecraft.util.math.BlockPos) MooshroomEntity(net.minecraft.entity.passive.MooshroomEntity) CowEntity(net.minecraft.entity.passive.CowEntity) FlowerPotBlock(net.minecraft.block.FlowerPotBlock)

Example 5 with HoeItem

use of net.minecraft.item.HoeItem in project RPGStats by P03W.

the class OnSneakLogic method doLogic.

public static void doLogic(boolean isSneaking, ServerPlayerEntity playerEntity) {
    Random random = new Random();
    // Check if all conditions met
    if (isSneaking && playerEntity.getMainHandStack().getItem() instanceof HoeItem && new Random().nextBoolean()) {
        int level = RPGStats.getComponentLevel(CustomComponents.FARMING, playerEntity);
        int amount = 0;
        if (level >= 50 && RPGStats.getConfig().toggles.farming.enableLv50Buff) {
            amount = 5;
        } else if (level >= 25 && RPGStats.getConfig().toggles.farming.enableLv25Buff) {
            amount = 3;
        }
        // In a 3x3 or 5x5 area, there is a 90% chance to grow any Fertilizable blocks
        if (amount > 0) {
            World world = playerEntity.world;
            BlockPos blockPos = playerEntity.getBlockPos();
            for (int y = -1; y <= 1; y++) {
                for (int x = -amount; x <= amount; x++) {
                    for (int z = -amount; z <= amount; z++) {
                        BlockPos nextPos = blockPos.add(x, y, z);
                        BlockState bs = world.getBlockState(nextPos);
                        if (bs.getBlock() instanceof Fertilizable) {
                            if (random.nextDouble() > 0.9) {
                                ((Fertilizable) bs.getBlock()).grow((ServerWorld) world, world.random, nextPos, bs);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) Random(java.util.Random) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ServerWorld(net.minecraft.server.world.ServerWorld) HoeItem(net.minecraft.item.HoeItem) Fertilizable(net.minecraft.block.Fertilizable)

Aggregations

HoeItem (net.minecraft.item.HoeItem)5 BlockPos (net.minecraft.util.math.BlockPos)3 Map (java.util.Map)2 BlockState (net.minecraft.block.BlockState)2 Item (net.minecraft.item.Item)2 ServerWorld (net.minecraft.server.world.ServerWorld)2 CarpetExtraSettings (carpetextra.CarpetExtraSettings)1 BlazePowderDispenserBehavior (carpetextra.dispenser.behaviors.BlazePowderDispenserBehavior)1 CarvePumpkinDispenserBehavior (carpetextra.dispenser.behaviors.CarvePumpkinDispenserBehavior)1 CauldronEmptyingDispenserBehavior (carpetextra.dispenser.behaviors.CauldronEmptyingDispenserBehavior)1 CauldronFillingDispenserBehavior (carpetextra.dispenser.behaviors.CauldronFillingDispenserBehavior)1 CauldronWaterDispenserBehavior (carpetextra.dispenser.behaviors.CauldronWaterDispenserBehavior)1 DragonBreathDispenserBehavior (carpetextra.dispenser.behaviors.DragonBreathDispenserBehavior)1 FeedAnimalDispenserBehavior (carpetextra.dispenser.behaviors.FeedAnimalDispenserBehavior)1 FeedMooshroomDispenserBehavior (carpetextra.dispenser.behaviors.FeedMooshroomDispenserBehavior)1 FillMinecartDispenserBehavior (carpetextra.dispenser.behaviors.FillMinecartDispenserBehavior)1 FireChargeDispenserBehavior (carpetextra.dispenser.behaviors.FireChargeDispenserBehavior)1 FlowerPotDispenserBehavior (carpetextra.dispenser.behaviors.FlowerPotDispenserBehavior)1 MilkAnimalDispenserBehavior (carpetextra.dispenser.behaviors.MilkAnimalDispenserBehavior)1 MilkMooshroomDispenserBehavior (carpetextra.dispenser.behaviors.MilkMooshroomDispenserBehavior)1