Search in sources :

Example 1 with MushroomType

use of cech12.extendedmushrooms.item.MushroomType 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)

Example 2 with MushroomType

use of cech12.extendedmushrooms.item.MushroomType in project ExtendedMushrooms by cech12.

the class MushroomSheepEntity method mobInteract.

@Override
@Nonnull
public ActionResultType mobInteract(PlayerEntity player, @Nonnull Hand hand) {
    Item item = player.getItemInHand(hand).getItem();
    ActionResultType superResult = super.mobInteract(player, hand);
    if (superResult.consumesAction() && Config.SHEEP_ABSORB_MUSHROOM_TYPE_ENABLED.get() && item.is(Tags.Items.MUSHROOMS)) {
        // change mushroom type
        MushroomType type = MushroomType.byItemOrNull(item);
        if (type != null && type != this.getMushroomType()) {
            this.setMushroomType(type);
            this.activateMushroomEffect(type);
            return ActionResultType.SUCCESS;
        }
    }
    return superResult;
}
Also used : Item(net.minecraft.item.Item) ActionResultType(net.minecraft.util.ActionResultType) MushroomType(cech12.extendedmushrooms.item.MushroomType) Nonnull(javax.annotation.Nonnull)

Aggregations

MushroomType (cech12.extendedmushrooms.item.MushroomType)2 MushroomSheepEntity (cech12.extendedmushrooms.entity.passive.MushroomSheepEntity)1 Nonnull (javax.annotation.Nonnull)1 SheepEntity (net.minecraft.entity.passive.SheepEntity)1 Item (net.minecraft.item.Item)1 ActionResultType (net.minecraft.util.ActionResultType)1 BlockPos (net.minecraft.util.math.BlockPos)1