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;
}
}
}
}
}
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;
}
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();
}
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;
}
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);
}
}
}
}
}
}
}
}
Aggregations