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);
}
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;
}
Aggregations