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