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