Search in sources :

Example 1 with CowEntity

use of net.minecraft.entity.passive.CowEntity in project Culinaire by DawnTeamMC.

the class CowEntityMixin method commonExpansion_interactMob.

@Inject(method = "interactMob", at = @At(value = "HEAD"), cancellable = true)
public void commonExpansion_interactMob(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> info) {
    CowEntity cowEntity = (CowEntity) (Object) this;
    ItemStack itemStack = player.getStackInHand(hand);
    if (itemStack.getItem() == Items.GLASS_BOTTLE && !cowEntity.isBaby()) {
        player.playSound(SoundEvents.ENTITY_COW_MILK, 1.0F, 1.0F);
        ItemStack itemStack2 = ItemUsage.method_30012(itemStack, player, CulinaireItems.MILK_BOTTLE.getDefaultStack());
        player.setStackInHand(hand, itemStack2);
        info.setReturnValue(ActionResult.success(cowEntity.world.isClient));
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) CowEntity(net.minecraft.entity.passive.CowEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with CowEntity

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

the class EntityAIWorkCowboy method milkCows.

/**
 * Makes the Cowboy "Milk" the cows (Honestly all he does is swap an empty bucket for a milk bucket, there's no actual "Milk" method in {@link CowEntity}
 *
 * @return The next {@link IAIState}
 */
private IAIState milkCows() {
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(TranslationConstants.COM_MINECOLONIES_COREMOD_STATUS_COWBOY_MILKING));
    worker.getCitizenData().setVisibleStatus(HERD_COW);
    if (!worker.getCitizenInventoryHandler().hasItemInInventory(getBreedingItem().getItem()) && InventoryUtils.getCountFromBuilding(getOwnBuilding(), new ItemStorage(new ItemStack(Items.BUCKET, 1))) > 1) {
        if (!walkToBuilding()) {
            checkAndTransferFromHut(new ItemStack(Items.BUCKET, 1));
        } else {
            return DECIDE;
        }
    }
    final CowEntity cow = searchForAnimals().stream().findFirst().orElse(null);
    if (cow == null) {
        return DECIDE;
    }
    if (!walkingToAnimal(cow) && equipItem(Hand.MAIN_HAND, new ItemStack(Items.BUCKET, 1))) {
        if (InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), new ItemStack(Items.MILK_BUCKET))) {
            worker.getCitizenItemHandler().removeHeldItem();
            equipItem(Hand.MAIN_HAND, new ItemStack(Items.MILK_BUCKET));
            InventoryUtils.tryRemoveStackFromItemHandler(worker.getInventoryCitizen(), new ItemStack(Items.BUCKET, 1));
        }
        incrementActionsDoneAndDecSaturation();
        worker.getCitizenExperienceHandler().addExperience(1.0);
    }
    return DECIDE;
}
Also used : TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) CowEntity(net.minecraft.entity.passive.CowEntity) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Example 3 with CowEntity

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

the class MushroomSporesItem method interactLivingEntity.

@Override
public ActionResultType interactLivingEntity(ItemStack stack, PlayerEntity playerIn, LivingEntity target, Hand hand) {
    boolean itemUsed = false;
    World world = target.level;
    if (!world.isClientSide && world instanceof ServerWorld) {
        if (target instanceof CowEntity && !(target instanceof MooshroomEntity)) {
            // Cow to Mooshroom
            target.setSpeed(0);
            // create mooshroom
            MooshroomEntity mooshroom = EntityType.MOOSHROOM.create(target.level);
            if (mooshroom != null) {
                mooshroom.copyPosition(target);
                mooshroom.finalizeSpawn((ServerWorld) world, world.getCurrentDifficultyAt(target.blockPosition()), SpawnReason.CONVERSION, null, null);
                mooshroom.setAge(((CowEntity) target).getAge());
                if (target.hasCustomName()) {
                    mooshroom.setCustomName(target.getCustomName());
                    mooshroom.setCustomNameVisible(target.isCustomNameVisible());
                }
                mooshroom.setHealth(target.getHealth());
                // replace cow with new mooshroom
                target.remove();
                world.addFreshEntity(mooshroom);
                mooshroom.playSound(SoundEvents.ZOMBIE_VILLAGER_CONVERTED, 2.0F, 1.0F);
                // remove one item
                stack.setCount(stack.getCount() - 1);
                itemUsed = true;
            }
        } else if (target instanceof SheepEntity && !(target instanceof MushroomSheepEntity)) {
            // Sheep to Mushroom Sheep
            MushroomSheepEntity.replaceSheep((SheepEntity) target, null);
            itemUsed = true;
        }
    }
    if (itemUsed) {
        // remove one item
        stack.setCount(stack.getCount() - 1);
        return ActionResultType.SUCCESS;
    }
    return ActionResultType.PASS;
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) MushroomSheepEntity(cech12.extendedmushrooms.entity.passive.MushroomSheepEntity) SheepEntity(net.minecraft.entity.passive.SheepEntity) MushroomSheepEntity(cech12.extendedmushrooms.entity.passive.MushroomSheepEntity) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World) MooshroomEntity(net.minecraft.entity.passive.MooshroomEntity) CowEntity(net.minecraft.entity.passive.CowEntity)

Example 4 with CowEntity

use of net.minecraft.entity.passive.CowEntity in project quilt-standard-libraries by QuiltMC.

the class QuiltDimensionTest method readyServer.

@Override
public void readyServer(MinecraftServer server) {
    ServerWorld overworld = server.getWorld(World.OVERWORLD);
    ServerWorld targetWorld = server.getWorld(WORLD_KEY);
    if (targetWorld == null) {
        throw new AssertionError("Test world somehow doesn't exist.");
    }
    CowEntity cow = EntityType.COW.create(overworld);
    if (!cow.world.getRegistryKey().equals(World.OVERWORLD)) {
        throw new AssertionError("Cow was spawned but isn't in the overworld.");
    }
    var target = new TeleportTarget(Vec3d.ZERO, new Vec3d(1, 1, 1), 45f, 60f);
    CowEntity teleportedEntity = QuiltDimensions.teleport(cow, targetWorld, target);
    if (teleportedEntity == null || !teleportedEntity.world.getRegistryKey().equals(WORLD_KEY)) {
        throw new AssertionError("Cow was not teleported correctly.");
    }
    if (!teleportedEntity.getPos().equals(target.position)) {
        throw new AssertionError("Cow was moved to different world, but not to the correct location.");
    }
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) TeleportTarget(net.minecraft.world.TeleportTarget) CowEntity(net.minecraft.entity.passive.CowEntity) Vec3d(net.minecraft.util.math.Vec3d)

Example 5 with CowEntity

use of net.minecraft.entity.passive.CowEntity in project minecolonies by Minecolonies.

the class EntityAIWorkCowboy method milkCows.

/**
 * Makes the Cowboy "Milk" the cows (Honestly all he does is swap an empty bucket for a milk bucket, there's no actual "Milk" method in {@link CowEntity}
 *
 * @return The next {@link IAIState}
 */
private IAIState milkCows() {
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(TranslationConstants.COM_MINECOLONIES_COREMOD_STATUS_COWBOY_MILKING));
    worker.getCitizenData().setVisibleStatus(HERD_COW);
    if (!worker.getCitizenInventoryHandler().hasItemInInventory(getBreedingItem().getItem()) && InventoryUtils.hasBuildingEnoughElseCount(building, new ItemStorage(new ItemStack(Items.BUCKET, 1)), 2) > 1) {
        if (!walkToBuilding()) {
            checkAndTransferFromHut(new ItemStack(Items.BUCKET, 1));
        } else {
            return DECIDE;
        }
    }
    final CowEntity cow = searchForAnimals().stream().findFirst().orElse(null);
    if (cow == null) {
        return DECIDE;
    }
    if (!walkingToAnimal(cow) && equipItem(Hand.MAIN_HAND, new ItemStack(Items.BUCKET, 1))) {
        if (InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), new ItemStack(Items.MILK_BUCKET))) {
            worker.getCitizenItemHandler().removeHeldItem();
            equipItem(Hand.MAIN_HAND, new ItemStack(Items.MILK_BUCKET));
            InventoryUtils.tryRemoveStackFromItemHandler(worker.getInventoryCitizen(), new ItemStack(Items.BUCKET, 1));
        }
        incrementActionsDoneAndDecSaturation();
        worker.getCitizenExperienceHandler().addExperience(1.0);
    }
    return DECIDE;
}
Also used : TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ItemStack(net.minecraft.item.ItemStack) CowEntity(net.minecraft.entity.passive.CowEntity) ItemStorage(com.minecolonies.api.crafting.ItemStorage)

Aggregations

CowEntity (net.minecraft.entity.passive.CowEntity)9 ItemStack (net.minecraft.item.ItemStack)6 ServerWorld (net.minecraft.server.world.ServerWorld)4 ItemStorage (com.minecolonies.api.crafting.ItemStorage)2 DispenserBlock (net.minecraft.block.DispenserBlock)2 EntityType (net.minecraft.entity.EntityType)2 AnimalEntity (net.minecraft.entity.passive.AnimalEntity)2 GoatEntity (net.minecraft.entity.passive.GoatEntity)2 Items (net.minecraft.item.Items)2 EntityPredicates (net.minecraft.predicate.entity.EntityPredicates)2 BlockPointer (net.minecraft.util.math.BlockPointer)2 BlockPos (net.minecraft.util.math.BlockPos)2 Box (net.minecraft.util.math.Box)2 CarpetExtraSettings (carpetextra.CarpetExtraSettings)1 DispenserBehaviorHelper (carpetextra.dispenser.DispenserBehaviorHelper)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