Search in sources :

Example 1 with SheepEntity

use of net.minecraft.entity.passive.SheepEntity in project EdenClient by HahaOO7.

the class AutoSheer method onTick.

private void onTick(ClientPlayerEntity player) {
    if (!enabled)
        return;
    ClientPlayerInteractionManager interactionManager = MinecraftClient.getInstance().interactionManager;
    if (interactionManager == null)
        return;
    Vec3d pos = player.getPos();
    PlayerInventory inv = player.getInventory();
    Hand shearHand;
    if (inv.getMainHandStack().getItem() == Items.SHEARS)
        shearHand = Hand.MAIN_HAND;
    else if (inv.offHand.get(0).getItem() == Items.SHEARS)
        shearHand = Hand.OFF_HAND;
    else
        return;
    if (shearHand == Hand.MAIN_HAND) {
        player.clientWorld.getEntitiesByClass(SheepEntity.class, player.getBoundingBox().expand(5), SheepEntity::isShearable).forEach(sheep -> {
            if (!sheep.isShearable())
                return;
            if (sheep.getPos().squaredDistanceTo(pos) < 25) {
                interactionManager.interactEntity(player, sheep, Hand.MAIN_HAND);
            }
        });
    } else {
        player.clientWorld.getEntitiesByClass(SheepEntity.class, player.getBoundingBox().expand(5), SheepEntity::isShearable).forEach(sheep -> {
            if (!sheep.isShearable())
                return;
            if (sheep.getPos().squaredDistanceTo(pos) < 25) {
                interactionManager.interactEntity(player, sheep, Hand.MAIN_HAND);
                interactionManager.interactEntity(player, sheep, Hand.OFF_HAND);
            }
        });
    }
}
Also used : ClientPlayerInteractionManager(net.minecraft.client.network.ClientPlayerInteractionManager) SheepEntity(net.minecraft.entity.passive.SheepEntity) PlayerInventory(net.minecraft.entity.player.PlayerInventory) Hand(net.minecraft.util.Hand) Vec3d(net.minecraft.util.math.Vec3d)

Example 2 with SheepEntity

use of net.minecraft.entity.passive.SheepEntity in project Jineric-Mod by Jiingy.

the class ManxLoaghtan method getChildColor.

private DyeColor getChildColor(AnimalEntity firstParent, AnimalEntity secondParent) {
    DyeColor dyeColor = ((SheepEntity) firstParent).getColor();
    DyeColor dyeColor2 = ((SheepEntity) secondParent).getColor();
    CraftingInventory craftingInventory = createDyeMixingCraftingInventory(dyeColor, dyeColor2);
    return (DyeColor) this.world.getRecipeManager().getFirstMatch(RecipeType.CRAFTING, craftingInventory, this.world).map(recipe -> recipe.craft(craftingInventory)).map(ItemStack::getItem).filter(DyeItem.class::isInstance).map(DyeItem.class::cast).map(DyeItem::getColor).orElseGet(() -> this.world.random.nextBoolean() ? dyeColor : dyeColor2);
}
Also used : CraftingInventory(net.minecraft.inventory.CraftingInventory) SheepEntity(net.minecraft.entity.passive.SheepEntity) DyeItem(net.minecraft.item.DyeItem) DyeColor(net.minecraft.util.DyeColor)

Example 3 with SheepEntity

use of net.minecraft.entity.passive.SheepEntity in project minecolonies by ldtteam.

the class EntityAIWorkShepherd method shearSheep.

/**
 * Shears a sheep, with a chance of dying it!
 *
 * @return The next {@link IAIState}
 */
private IAIState shearSheep() {
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(TranslationConstants.COM_MINECOLONIES_COREMOD_STATUS_SHEPHERD_SHEARING));
    final List<SheepEntity> sheeps = searchForAnimals();
    if (sheeps.isEmpty()) {
        return DECIDE;
    }
    if (!equipTool(Hand.MAIN_HAND, ToolType.SHEARS)) {
        return PREPARING;
    }
    final SheepEntity sheep = sheeps.stream().filter(sheepie -> !sheepie.isSheared() && !sheepie.isBaby()).findFirst().orElse(null);
    if (worker.getMainHandItem() != null && sheep != null) {
        if (walkingToAnimal(sheep)) {
            return getState();
        }
        int enchantmentLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_FORTUNE, worker.getMainHandItem());
        enchantmentLevel *= Math.max(1.0, (getPrimarySkillLevel() / 5.0));
        worker.swing(Hand.MAIN_HAND);
        final List<ItemStack> items = new ArrayList<>();
        if (!this.world.isClientSide) {
            sheep.setSheared(true);
            int qty = 1 + worker.getRandom().nextInt(enchantmentLevel + 1);
            for (int j = 0; j < qty; ++j) {
                items.add(new ItemStack(ITEM_BY_DYE.get(sheep.getColor())));
            }
        }
        sheep.playSound(SoundEvents.SHEEP_SHEAR, 1.0F, 1.0F);
        dyeSheepChance(sheep);
        worker.getCitizenItemHandler().damageItemInHand(Hand.MAIN_HAND, 1);
        worker.getCitizenExperienceHandler().addExperience(XP_PER_ACTION);
        incrementActionsDoneAndDecSaturation();
        for (final ItemStack item : items) {
            InventoryUtils.transferItemStackIntoNextBestSlotInItemHandler(item, (worker.getInventoryCitizen()));
        }
    }
    return DECIDE;
}
Also used : SheepEntity(net.minecraft.entity.passive.SheepEntity) ArrayList(java.util.ArrayList) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack)

Example 4 with SheepEntity

use of net.minecraft.entity.passive.SheepEntity in project ExtendedMushrooms by cech12.

the class ExtendedMushrooms method onEntityJoinWorld.

/**
 * Add eat mushroom goal to sheep entities when configured.
 */
@SubscribeEvent
public static void onEntityJoinWorld(EntityJoinWorldEvent event) {
    if (Config.SHEEP_EAT_MUSHROOM_FROM_GROUND_ENABLED.get()) {
        if (event.getEntity() instanceof SheepEntity) {
            // also mushroom sheep
            SheepEntity sheep = ((SheepEntity) event.getEntity());
            sheep.goalSelector.addGoal(5, new EatMushroomGoal(sheep));
        }
    }
}
Also used : MushroomSheepEntity(cech12.extendedmushrooms.entity.passive.MushroomSheepEntity) SheepEntity(net.minecraft.entity.passive.SheepEntity) EatMushroomGoal(cech12.extendedmushrooms.entity.ai.goal.EatMushroomGoal) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 5 with SheepEntity

use of net.minecraft.entity.passive.SheepEntity in project ExtendedMushrooms by cech12.

the class EatMushroomGoal method tick.

/**
 * Keep ticking a continuous task that has already been started
 */
@Override
public void tick() {
    this.eatingTimer = Math.max(0, this.eatingTimer - 1);
    if (this.eatingTimer == 4) {
        BlockPos blockPos = getBlockPos();
        if (this.isEntityOnMushroom()) {
            MushroomType mushroomType = MushroomType.byItemOrNull(this.entityWorld.getBlockState(this.eaterEntity.blockPosition()).getBlock().asItem());
            if (this.entityWorld.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) {
                this.entityWorld.destroyBlock(blockPos, false);
            }
            this.eaterEntity.ate();
            if (Config.SHEEP_ABSORB_MUSHROOM_TYPE_ENABLED.get()) {
                if (this.eaterEntity instanceof SheepEntity && mushroomType != null) {
                    if (this.eaterEntity instanceof MushroomSheepEntity) {
                        MushroomSheepEntity mushroomSheep = (MushroomSheepEntity) this.eaterEntity;
                        mushroomSheep.setMushroomType(mushroomType);
                        mushroomSheep.activateMushroomEffect(mushroomType);
                    } else {
                        MushroomSheepEntity.replaceSheep((SheepEntity) this.eaterEntity, mushroomType);
                    }
                }
            }
        }
    }
}
Also used : MushroomSheepEntity(cech12.extendedmushrooms.entity.passive.MushroomSheepEntity) SheepEntity(net.minecraft.entity.passive.SheepEntity) MushroomType(cech12.extendedmushrooms.item.MushroomType) MushroomSheepEntity(cech12.extendedmushrooms.entity.passive.MushroomSheepEntity) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

SheepEntity (net.minecraft.entity.passive.SheepEntity)12 ArrayList (java.util.ArrayList)4 MushroomSheepEntity (cech12.extendedmushrooms.entity.passive.MushroomSheepEntity)3 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)2 Entity (net.minecraft.entity.Entity)2 ItemStack (net.minecraft.item.ItemStack)2 ShearsItem (net.minecraft.item.ShearsItem)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2 EatMushroomGoal (cech12.extendedmushrooms.entity.ai.goal.EatMushroomGoal)1 MushroomType (cech12.extendedmushrooms.item.MushroomType)1 EventHandler (mathax.client.eventbus.EventHandler)1 FindItemResult (mathax.client.utils.player.FindItemResult)1 FindItemResult (meteordevelopment.meteorclient.utils.player.FindItemResult)1 EventHandler (meteordevelopment.orbit.EventHandler)1 ClientPlayerInteractionManager (net.minecraft.client.network.ClientPlayerInteractionManager)1 CowEntity (net.minecraft.entity.passive.CowEntity)1 MooshroomEntity (net.minecraft.entity.passive.MooshroomEntity)1 PlayerInventory (net.minecraft.entity.player.PlayerInventory)1 CraftingInventory (net.minecraft.inventory.CraftingInventory)1 DyeItem (net.minecraft.item.DyeItem)1