Search in sources :

Example 1 with MooshroomEntity_StatusEffectAccessorMixin

use of carpetextra.mixins.MooshroomEntity_StatusEffectAccessorMixin in project carpet-extra by gnembon.

the class MilkMooshroomDispenserBehavior method getStewType.

private static ItemStack getStewType(List<MooshroomEntity> mooshrooms) {
    // check each mooshroom for stew effect, return suspicious stew of that type if exists
    for (MooshroomEntity mooshroom : mooshrooms) {
        MooshroomEntity_StatusEffectAccessorMixin mooshroomAccessor = (MooshroomEntity_StatusEffectAccessorMixin) mooshroom;
        StatusEffect stewEffect = mooshroomAccessor.getStewEffect();
        if (stewEffect != null) {
            // create suspicious stew and add mooshroom's stew effect to it
            ItemStack stewStack = new ItemStack(Items.SUSPICIOUS_STEW);
            SuspiciousStewItem.addEffectToStew(stewStack, stewEffect, mooshroomAccessor.getStewEffectDuration());
            // clear mooshroom's stew effect
            mooshroomAccessor.setStatusEffect(null);
            mooshroomAccessor.setStewEffectDuration(0);
            return stewStack;
        }
    }
    // return regular mushroom stew if no stew effects exist
    return new ItemStack(Items.MUSHROOM_STEW);
}
Also used : MooshroomEntity_StatusEffectAccessorMixin(carpetextra.mixins.MooshroomEntity_StatusEffectAccessorMixin) StatusEffect(net.minecraft.entity.effect.StatusEffect) MooshroomEntity(net.minecraft.entity.passive.MooshroomEntity) ItemStack(net.minecraft.item.ItemStack)

Example 2 with MooshroomEntity_StatusEffectAccessorMixin

use of carpetextra.mixins.MooshroomEntity_StatusEffectAccessorMixin in project carpet-extra by gnembon.

the class FeedMooshroomDispenserBehavior method dispenseSilently.

@Override
protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
    this.setSuccess(true);
    ServerWorld world = pointer.getWorld();
    BlockPos frontBlockPos = pointer.getPos().offset(pointer.getBlockState().get(DispenserBlock.FACING));
    // check if item is in SMALL_FLOWERS item tag
    if (stack.isIn(ItemTags.SMALL_FLOWERS)) {
        // get brown mooshrooms in front of dispenser
        List<MooshroomEntity> mooshrooms = world.getEntitiesByType(EntityType.MOOSHROOM, new Box(frontBlockPos), EntityPredicates.VALID_LIVING_ENTITY.and((mooshroomEntity) -> {
            return ((MooshroomEntity) mooshroomEntity).getMooshroomType() == MooshroomEntity.Type.BROWN;
        }));
        // check all mooshrooms
        for (MooshroomEntity mooshroom : mooshrooms) {
            MooshroomEntity_StatusEffectAccessorMixin mooshroomAccessor = (MooshroomEntity_StatusEffectAccessorMixin) mooshroom;
            // check if mooshroom has no stew effect
            if (mooshroomAccessor.getStewEffect() == null) {
                // get stew effect and length for flower
                Optional<Pair<StatusEffect, Integer>> effect = mooshroomAccessor.invokeGetStewEffectFrom(stack);
                // check if effect is present
                if (effect.isPresent()) {
                    Pair<StatusEffect, Integer> pair = effect.get();
                    // set stew effect for mooshroom
                    mooshroomAccessor.setStatusEffect(pair.getLeft());
                    mooshroomAccessor.setStewEffectDuration(pair.getRight());
                    // play sound effect and show particles
                    world.playSound(null, frontBlockPos, SoundEvents.ENTITY_MOOSHROOM_EAT, SoundCategory.NEUTRAL, 2.0F, 1.0F);
                    world.spawnParticles(ParticleTypes.EFFECT, mooshroom.getX() + mooshroom.getRandom().nextDouble() / 2.0D, mooshroom.getBodyY(0.5D), mooshroom.getZ() + mooshroom.getRandom().nextDouble() / 2.0D, 1, 0.0D, mooshroom.getRandom().nextDouble() / 5.0D, 0.0D, 0.01D);
                    // remove a flower and return stack
                    stack.decrement(1);
                    return stack;
                }
            }
        }
    }
    // fail to dispense
    this.setSuccess(false);
    return stack;
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) FallibleItemDispenserBehavior(net.minecraft.block.dispenser.FallibleItemDispenserBehavior) EntityType(net.minecraft.entity.EntityType) ItemTags(net.minecraft.tag.ItemTags) ServerWorld(net.minecraft.server.world.ServerWorld) Box(net.minecraft.util.math.Box) BlockPointer(net.minecraft.util.math.BlockPointer) BlockPos(net.minecraft.util.math.BlockPos) MooshroomEntity(net.minecraft.entity.passive.MooshroomEntity) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) StatusEffect(net.minecraft.entity.effect.StatusEffect) Pair(org.apache.commons.lang3.tuple.Pair) SoundEvents(net.minecraft.sound.SoundEvents) ParticleTypes(net.minecraft.particle.ParticleTypes) EntityPredicates(net.minecraft.predicate.entity.EntityPredicates) Optional(java.util.Optional) MooshroomEntity_StatusEffectAccessorMixin(carpetextra.mixins.MooshroomEntity_StatusEffectAccessorMixin) DispenserBlock(net.minecraft.block.DispenserBlock) SoundCategory(net.minecraft.sound.SoundCategory) MooshroomEntity_StatusEffectAccessorMixin(carpetextra.mixins.MooshroomEntity_StatusEffectAccessorMixin) StatusEffect(net.minecraft.entity.effect.StatusEffect) BlockPos(net.minecraft.util.math.BlockPos) Box(net.minecraft.util.math.Box) MooshroomEntity(net.minecraft.entity.passive.MooshroomEntity) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

MooshroomEntity_StatusEffectAccessorMixin (carpetextra.mixins.MooshroomEntity_StatusEffectAccessorMixin)2 StatusEffect (net.minecraft.entity.effect.StatusEffect)2 MooshroomEntity (net.minecraft.entity.passive.MooshroomEntity)2 ItemStack (net.minecraft.item.ItemStack)2 List (java.util.List)1 Optional (java.util.Optional)1 DispenserBlock (net.minecraft.block.DispenserBlock)1 FallibleItemDispenserBehavior (net.minecraft.block.dispenser.FallibleItemDispenserBehavior)1 EntityType (net.minecraft.entity.EntityType)1 ParticleTypes (net.minecraft.particle.ParticleTypes)1 EntityPredicates (net.minecraft.predicate.entity.EntityPredicates)1 ServerWorld (net.minecraft.server.world.ServerWorld)1 SoundCategory (net.minecraft.sound.SoundCategory)1 SoundEvents (net.minecraft.sound.SoundEvents)1 ItemTags (net.minecraft.tag.ItemTags)1 BlockPointer (net.minecraft.util.math.BlockPointer)1 BlockPos (net.minecraft.util.math.BlockPos)1 Box (net.minecraft.util.math.Box)1 Pair (org.apache.commons.lang3.tuple.Pair)1