Search in sources :

Example 1 with VillagerEntity

use of net.minecraft.entity.merchant.villager.VillagerEntity in project Vampirism by TeamLapen.

the class ConvertedVillagerEntity method cureEntity.

@Override
public VillagerEntity cureEntity(ServerWorld world, CreatureEntity entity, EntityType<VillagerEntity> newType) {
    VillagerEntity villager = ICurableConvertedCreature.super.cureEntity(world, entity, newType);
    villager.setVillagerData(this.getVillagerData());
    villager.setGossips(this.getGossips().store(NBTDynamicOps.INSTANCE).getValue());
    villager.setOffers(this.getOffers());
    villager.setVillagerXp(this.getVillagerXp());
    if (this.conversationStarter != null) {
        PlayerEntity playerentity = world.getPlayerByUUID(this.conversationStarter);
        if (playerentity instanceof ServerPlayerEntity) {
            ModAdvancements.TRIGGER_CURED_VAMPIRE_VILLAGER.trigger((ServerPlayerEntity) playerentity, this, villager);
            world.onReputationEvent(IReputationType.ZOMBIE_VILLAGER_CURED, playerentity, villager);
        }
    }
    return villager;
}
Also used : VampirismVillagerEntity(de.teamlapen.vampirism.entity.VampirismVillagerEntity) VillagerEntity(net.minecraft.entity.merchant.villager.VillagerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 2 with VillagerEntity

use of net.minecraft.entity.merchant.villager.VillagerEntity in project Vampirism by TeamLapen.

the class ModEntityEventHandler method onEntityJoinWorld.

@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event) {
    if (!event.getWorld().isClientSide()) {
        if (event.getEntity() instanceof IAdjustableLevel) {
            IAdjustableLevel entity = (IAdjustableLevel) event.getEntity();
            if (entity.getLevel() == -1) {
                Difficulty d = DifficultyCalculator.findDifficultyForPos(event.getWorld(), event.getEntity().blockPosition(), 30);
                int l = entity.suggestLevel(d);
                if (l > entity.getMaxLevel()) {
                    l = entity.getMaxLevel();
                } else if (l < 0) {
                    event.setCanceled(true);
                }
                entity.setLevel(l);
                if (entity instanceof CreatureEntity) {
                    ((CreatureEntity) entity).setHealth(((CreatureEntity) entity).getMaxHealth());
                }
            }
        }
        // Creeper AI changes for AvoidedByCreepers Skill
        if (VampirismConfig.BALANCE.creeperIgnoreVampire.get()) {
            if (event.getEntity() instanceof CreeperEntity) {
                ((CreeperEntity) event.getEntity()).goalSelector.addGoal(3, new AvoidEntityGoal<>((CreeperEntity) event.getEntity(), PlayerEntity.class, 20, 1.1, 1.3, Helper::isVampire));
                makeVampireFriendly("creeper", (CreeperEntity) event.getEntity(), NearestAttackableTargetGoal.class, PlayerEntity.class, 1, (entity, predicate) -> new NearestAttackableTargetGoal<>(entity, PlayerEntity.class, 10, true, false, predicate), type -> type == EntityType.CREEPER);
                return;
            }
        }
        // Zombie AI changes
        if (VampirismConfig.BALANCE.zombieIgnoreVampire.get()) {
            if (event.getEntity() instanceof ZombieEntity) {
                makeVampireFriendly("zombie", (ZombieEntity) event.getEntity(), NearestAttackableTargetGoal.class, PlayerEntity.class, 2, (entity, predicate) -> entity instanceof DrownedEntity ? new NearestAttackableTargetGoal<>(entity, PlayerEntity.class, 10, true, false, predicate.and(((DrownedEntity) entity)::okTarget)) : new NearestAttackableTargetGoal<>(entity, PlayerEntity.class, 10, true, false, predicate), type -> type == EntityType.ZOMBIE || type == EntityType.HUSK || type == EntityType.ZOMBIE_VILLAGER || type == EntityType.DROWNED);
                // Also replace attack villager task for entities that have it
                makeVampireFriendly("villager zombie", (ZombieEntity) event.getEntity(), NearestAttackableTargetGoal.class, AbstractVillagerEntity.class, 3, (entity, predicate) -> new NearestAttackableTargetGoal<>(entity, AbstractVillagerEntity.class, 10, true, false, predicate), type -> type == EntityType.ZOMBIE || type == EntityType.HUSK || type == EntityType.ZOMBIE_VILLAGER || type == EntityType.DROWNED);
                return;
            }
        }
        if (VampirismConfig.BALANCE.skeletonIgnoreVampire.get()) {
            if (event.getEntity() instanceof SkeletonEntity || event.getEntity() instanceof StrayEntity) {
                makeVampireFriendly("skeleton", (AbstractSkeletonEntity) event.getEntity(), NearestAttackableTargetGoal.class, PlayerEntity.class, 2, (entity, predicate) -> new NearestAttackableTargetGoal<>(entity, PlayerEntity.class, 10, true, false, predicate), type -> type == EntityType.SKELETON || type == EntityType.STRAY);
            }
        }
        if (event.getEntity() instanceof IronGolemEntity) {
            ((IronGolemEntity) event.getEntity()).targetSelector.addGoal(4, new GolemTargetNonVillageFactionGoal((IronGolemEntity) event.getEntity()));
            Goal mobTarget = null;
            for (PrioritizedGoal t : ((IronGolemEntity) event.getEntity()).targetSelector.availableGoals) {
                if (t.getGoal() instanceof NearestAttackableTargetGoal && t.getPriority() == 3 && MobEntity.class.equals(((NearestAttackableTargetGoal<?>) t.getGoal()).targetType)) {
                    mobTarget = t.getGoal();
                    break;
                }
            }
            if (mobTarget != null) {
                ((IronGolemEntity) event.getEntity()).targetSelector.removeGoal(mobTarget);
                ((IronGolemEntity) event.getEntity()).targetSelector.addGoal(3, new NearestAttackableTargetGoal<>((IronGolemEntity) event.getEntity(), MobEntity.class, 5, false, false, entity -> entity instanceof IMob && !(entity instanceof IFactionEntity) && !(entity instanceof CreeperEntity)));
            } else {
                if (warnAboutGolem) {
                    LOGGER.warn("Could not replace villager iron golem target task");
                    warnAboutGolem = false;
                }
            }
            return;
        }
        if (event.getEntity() instanceof VillagerEntity) {
            Optional<TotemTileEntity> tile = TotemHelper.getTotemNearPos(((ServerWorld) event.getWorld()), event.getEntity().blockPosition(), true);
            if (tile.filter(t -> VReference.HUNTER_FACTION.equals(t.getControllingFaction())).isPresent()) {
                ExtendedCreature.getSafe(event.getEntity()).ifPresent(e -> e.setPoisonousBlood(true));
            }
            return;
        }
    }
}
Also used : TotemTileEntity(de.teamlapen.vampirism.tileentity.TotemTileEntity) ServerWorld(net.minecraft.world.server.ServerWorld) DifficultyCalculator(de.teamlapen.vampirism.util.DifficultyCalculator) Object2BooleanMap(it.unimi.dsi.fastutil.objects.Object2BooleanMap) BiFunction(java.util.function.BiFunction) HunterBaseEntity(de.teamlapen.vampirism.entity.hunter.HunterBaseEntity) Object2BooleanArrayMap(it.unimi.dsi.fastutil.objects.Object2BooleanArrayMap) Block(net.minecraft.block.Block) GolemTargetNonVillageFactionGoal(de.teamlapen.vampirism.entity.goals.GolemTargetNonVillageFactionGoal) EventPriority(net.minecraftforge.eventbus.api.EventPriority) IFactionEntity(de.teamlapen.vampirism.api.entity.factions.IFactionEntity) Event(net.minecraftforge.eventbus.api.Event) CastleStairsBlock(de.teamlapen.vampirism.blocks.CastleStairsBlock) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) BlockState(net.minecraft.block.BlockState) IFactionSlayerItem(de.teamlapen.vampirism.api.items.IFactionSlayerItem) VillagerEntity(net.minecraft.entity.merchant.villager.VillagerEntity) IItemWithTier(de.teamlapen.vampirism.api.items.IItemWithTier) PlayerEntity(net.minecraft.entity.player.PlayerEntity) VampirePlayer(de.teamlapen.vampirism.player.vampire.VampirePlayer) Predicate(java.util.function.Predicate) MinionEntity(de.teamlapen.vampirism.entity.minion.MinionEntity) Set(java.util.Set) EntityJoinWorldEvent(net.minecraftforge.event.entity.EntityJoinWorldEvent) Difficulty(de.teamlapen.vampirism.api.difficulty.Difficulty) CastleSlabBlock(de.teamlapen.vampirism.blocks.CastleSlabBlock) Logger(org.apache.logging.log4j.Logger) EffectiveSide(net.minecraftforge.fml.common.thread.EffectiveSide) Optional(java.util.Optional) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) IFaction(de.teamlapen.vampirism.api.entity.factions.IFaction) VampirismPlayerAttributes(de.teamlapen.vampirism.player.VampirismPlayerAttributes) CastleBricksBlock(de.teamlapen.vampirism.blocks.CastleBricksBlock) PotionItem(net.minecraft.item.PotionItem) IronGolemEntity(net.minecraft.entity.passive.IronGolemEntity) VampirismConfig(de.teamlapen.vampirism.config.VampirismConfig) AbstractVillagerEntity(net.minecraft.entity.merchant.villager.AbstractVillagerEntity) HashSet(java.util.HashSet) ItemStack(net.minecraft.item.ItemStack) Helper(de.teamlapen.vampirism.util.Helper) Goal(net.minecraft.entity.ai.goal.Goal) AvoidEntityGoal(net.minecraft.entity.ai.goal.AvoidEntityGoal) net.minecraft.entity(net.minecraft.entity) IAdjustableLevel(de.teamlapen.vampirism.api.difficulty.IAdjustableLevel) NearestAttackableTargetGoal(net.minecraft.entity.ai.goal.NearestAttackableTargetGoal) VampirismVampireSword(de.teamlapen.vampirism.items.VampirismVampireSword) net.minecraftforge.event.entity.living(net.minecraftforge.event.entity.living) Nullable(javax.annotation.Nullable) IExtendedCreatureVampirism(de.teamlapen.vampirism.api.entity.IExtendedCreatureVampirism) VampirismAPI(de.teamlapen.vampirism.api.VampirismAPI) VampireBaseEntity(de.teamlapen.vampirism.entity.vampire.VampireBaseEntity) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) TotemHelper(de.teamlapen.vampirism.tileentity.TotemHelper) AttachCapabilitiesEvent(net.minecraftforge.event.AttachCapabilitiesEvent) REFERENCE(de.teamlapen.vampirism.REFERENCE) VReference(de.teamlapen.vampirism.api.VReference) EquipmentSlotType(net.minecraft.inventory.EquipmentSlotType) net.minecraft.entity.monster(net.minecraft.entity.monster) ResourceLocation(net.minecraft.util.ResourceLocation) EntityEvent(net.minecraftforge.event.entity.EntityEvent) LogManager(org.apache.logging.log4j.LogManager) VillagerEntity(net.minecraft.entity.merchant.villager.VillagerEntity) AbstractVillagerEntity(net.minecraft.entity.merchant.villager.AbstractVillagerEntity) Difficulty(de.teamlapen.vampirism.api.difficulty.Difficulty) NearestAttackableTargetGoal(net.minecraft.entity.ai.goal.NearestAttackableTargetGoal) PlayerEntity(net.minecraft.entity.player.PlayerEntity) AbstractVillagerEntity(net.minecraft.entity.merchant.villager.AbstractVillagerEntity) ServerWorld(net.minecraft.world.server.ServerWorld) GolemTargetNonVillageFactionGoal(de.teamlapen.vampirism.entity.goals.GolemTargetNonVillageFactionGoal) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) Goal(net.minecraft.entity.ai.goal.Goal) AvoidEntityGoal(net.minecraft.entity.ai.goal.AvoidEntityGoal) NearestAttackableTargetGoal(net.minecraft.entity.ai.goal.NearestAttackableTargetGoal) IronGolemEntity(net.minecraft.entity.passive.IronGolemEntity) GolemTargetNonVillageFactionGoal(de.teamlapen.vampirism.entity.goals.GolemTargetNonVillageFactionGoal) IFactionEntity(de.teamlapen.vampirism.api.entity.factions.IFactionEntity) IAdjustableLevel(de.teamlapen.vampirism.api.difficulty.IAdjustableLevel) TotemTileEntity(de.teamlapen.vampirism.tileentity.TotemTileEntity) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 3 with VillagerEntity

use of net.minecraft.entity.merchant.villager.VillagerEntity in project Vampirism by TeamLapen.

the class TotemTileEntity method spawnVillagerReplaceForced.

// client------------------------------------------------------------------------------------------------------------
@SuppressWarnings("ConstantConditions")
private void spawnVillagerReplaceForced(MobEntity oldEntity, boolean poisonousBlood) {
    VillagerEntity newVillager = EntityType.VILLAGER.create(this.level);
    ExtendedCreature.getSafe(newVillager).ifPresent(e -> e.setPoisonousBlood(poisonousBlood));
    newVillager.copyPosition(oldEntity);
    if (oldEntity instanceof VillagerEntity) {
        newVillager.restrictTo(oldEntity.getRestrictCenter(), (int) oldEntity.getRestrictRadius());
    }
    newVillager = VampirismEventFactory.fireSpawnNewVillagerEvent(this, oldEntity, newVillager, true, poisonousBlood);
    UtilLib.replaceEntity(oldEntity, newVillager);
}
Also used : ConvertedVillagerEntity(de.teamlapen.vampirism.entity.converted.ConvertedVillagerEntity) AggressiveVillagerEntity(de.teamlapen.vampirism.entity.hunter.AggressiveVillagerEntity) VillagerEntity(net.minecraft.entity.merchant.villager.VillagerEntity)

Example 4 with VillagerEntity

use of net.minecraft.entity.merchant.villager.VillagerEntity in project Vampirism by TeamLapen.

the class AggressiveVillagerEntity method stopVillageAttackDefense.

@Override
public void stopVillageAttackDefense() {
    VillagerEntity villager = EntityType.VILLAGER.create(this.level);
    assert villager != null;
    this.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
    CompoundNBT nbt = new CompoundNBT();
    this.saveWithoutId(nbt);
    villager.load(nbt);
    villager.setUUID(MathHelper.createInsecureUUID(this.random));
    UtilLib.replaceEntity(this, villager);
}
Also used : VampirismVillagerEntity(de.teamlapen.vampirism.entity.VampirismVillagerEntity) VillagerEntity(net.minecraft.entity.merchant.villager.VillagerEntity) CompoundNBT(net.minecraft.nbt.CompoundNBT)

Example 5 with VillagerEntity

use of net.minecraft.entity.merchant.villager.VillagerEntity in project Vampirism by TeamLapen.

the class TotemTileEntity method spawnVillagerDefault.

private void spawnVillagerDefault(boolean poisonousBlood) {
    // noinspection ConstantConditions
    VillagerEntity newVillager = EntityType.VILLAGER.create(this.level);
    // noinspection ConstantConditions
    ExtendedCreature.getSafe(newVillager).ifPresent(e -> e.setPoisonousBlood(poisonousBlood));
    newVillager = VampirismEventFactory.fireSpawnNewVillagerEvent(this, null, newVillager, false, poisonousBlood);
    spawnEntity(newVillager);
}
Also used : ConvertedVillagerEntity(de.teamlapen.vampirism.entity.converted.ConvertedVillagerEntity) AggressiveVillagerEntity(de.teamlapen.vampirism.entity.hunter.AggressiveVillagerEntity) VillagerEntity(net.minecraft.entity.merchant.villager.VillagerEntity)

Aggregations

VillagerEntity (net.minecraft.entity.merchant.villager.VillagerEntity)9 ConvertedVillagerEntity (de.teamlapen.vampirism.entity.converted.ConvertedVillagerEntity)4 AggressiveVillagerEntity (de.teamlapen.vampirism.entity.hunter.AggressiveVillagerEntity)4 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 VReference (de.teamlapen.vampirism.api.VReference)2 VampirismAPI (de.teamlapen.vampirism.api.VampirismAPI)2 IFaction (de.teamlapen.vampirism.api.entity.factions.IFaction)2 IFactionEntity (de.teamlapen.vampirism.api.entity.factions.IFactionEntity)2 VampirismConfig (de.teamlapen.vampirism.config.VampirismConfig)2 VampirismVillagerEntity (de.teamlapen.vampirism.entity.VampirismVillagerEntity)2 HunterBaseEntity (de.teamlapen.vampirism.entity.hunter.HunterBaseEntity)2 VampireBaseEntity (de.teamlapen.vampirism.entity.vampire.VampireBaseEntity)2 VampirismPlayerAttributes (de.teamlapen.vampirism.player.VampirismPlayerAttributes)2 TotemHelper (de.teamlapen.vampirism.tileentity.TotemHelper)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 CompoundNBT (net.minecraft.nbt.CompoundNBT)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 UtilLib (de.teamlapen.lib.lib.util.UtilLib)1