Search in sources :

Example 1 with MushroomSheepEntity

use of cech12.extendedmushrooms.entity.passive.MushroomSheepEntity 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 MushroomSheepEntity

use of cech12.extendedmushrooms.entity.passive.MushroomSheepEntity 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 3 with MushroomSheepEntity

use of cech12.extendedmushrooms.entity.passive.MushroomSheepEntity in project ExtendedMushrooms by cech12.

the class ExtendedMushrooms method onEntityInteract.

/**
 * Remove dye behaviour from mushroom sheeps.
 */
@SubscribeEvent
public static void onEntityInteract(PlayerInteractEvent.EntityInteract event) {
    ItemStack itemStack = event.getPlayer().getItemInHand(event.getHand());
    Entity entity = event.getTarget();
    // check for dye item and mushroom sheep entity
    if (entity instanceof MushroomSheepEntity && itemStack.getItem() instanceof DyeItem) {
        event.setCanceled(true);
        event.setCancellationResult(ActionResultType.FAIL);
    }
}
Also used : MushroomSheepEntity(cech12.extendedmushrooms.entity.passive.MushroomSheepEntity) Entity(net.minecraft.entity.Entity) SheepEntity(net.minecraft.entity.passive.SheepEntity) DyeItem(net.minecraft.item.DyeItem) MushroomSheepEntity(cech12.extendedmushrooms.entity.passive.MushroomSheepEntity) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

MushroomSheepEntity (cech12.extendedmushrooms.entity.passive.MushroomSheepEntity)3 SheepEntity (net.minecraft.entity.passive.SheepEntity)3 MushroomType (cech12.extendedmushrooms.item.MushroomType)1 Entity (net.minecraft.entity.Entity)1 CowEntity (net.minecraft.entity.passive.CowEntity)1 MooshroomEntity (net.minecraft.entity.passive.MooshroomEntity)1 DyeItem (net.minecraft.item.DyeItem)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 ServerWorld (net.minecraft.world.server.ServerWorld)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1