use of com.lying.variousoddities.network.PacketSyncLivingData in project VariousOddities by Lyinginbedmon.
the class VOBusServer method onPlayerLogInEvent.
@SubscribeEvent
public static void onPlayerLogInEvent(PlayerLoggedInEvent event) {
PlayerEntity player = event.getPlayer();
PacketHandler.sendTo((ServerPlayerEntity) player, new PacketSyncSpecies(VORegistries.SPECIES));
LivingData data = LivingData.forEntity(player);
if (data != null) {
PacketHandler.sendToAll((ServerWorld) player.getEntityWorld(), new PacketSyncLivingData(player.getUniqueID(), data));
data.getAbilities().markDirty();
if (!data.hasSelectedSpecies() && ConfigVO.MOBS.selectSpeciesOnLogin.get()) {
if (!player.getEntityWorld().isRemote)
PacketHandler.sendTo((ServerPlayerEntity) player, new PacketSpeciesOpenScreen());
player.addPotionEffect(new EffectInstance(Effects.RESISTANCE, Reference.Values.TICKS_PER_MINUTE * 15, 15, true, false));
}
}
}
use of com.lying.variousoddities.network.PacketSyncLivingData in project VariousOddities by Lyinginbedmon.
the class VOBusServer method addEntityBehaviours.
@SubscribeEvent
public static void addEntityBehaviours(EntityJoinWorldEvent event) {
Entity theEntity = event.getEntity();
if (theEntity instanceof LivingEntity && !theEntity.getEntityWorld().isRemote) {
LivingData data = LivingData.forEntity((LivingEntity) theEntity);
if (data != null && !theEntity.getEntityWorld().isRemote)
PacketHandler.sendToAll((ServerWorld) theEntity.getEntityWorld(), new PacketSyncLivingData(theEntity.getUniqueID(), data));
}
if (theEntity.getType() == EntityType.CAT || theEntity.getType() == EntityType.OCELOT) {
MobEntity feline = (MobEntity) theEntity;
if (ConfigVO.MOBS.aiSettings.isOddityAIEnabled(VOEntities.RAT))
feline.targetSelector.addGoal(1, new NearestAttackableTargetGoal<EntityRat>(feline, EntityRat.class, true));
if (ConfigVO.MOBS.aiSettings.isOddityAIEnabled(VOEntities.RAT_GIANT))
feline.targetSelector.addGoal(1, new NearestAttackableTargetGoal<EntityRatGiant>(feline, EntityRatGiant.class, true));
}
// Add sleep AI to mobs
if (theEntity instanceof MobEntity) {
MobEntity living = (MobEntity) theEntity;
living.goalSelector.addGoal(1, new EntityAISleep(living));
if (living instanceof CreatureEntity)
living.goalSelector.addGoal(1, new EntityAIFrightened((CreatureEntity) living));
}
// Spook worgs
if (event.getEntity().getType() == EntityType.LIGHTNING_BOLT) {
BlockPos pos = event.getEntity().getPosition();
AxisAlignedBB bounds = new AxisAlignedBB(0, 0, 0, 1, 256, 1).offset(pos.getX(), 0, pos.getZ()).grow(128, 0, 128);
for (EntityWorg worg : event.getEntity().getEntityWorld().getEntitiesWithinAABB(EntityWorg.class, bounds)) worg.spook();
}
}
use of com.lying.variousoddities.network.PacketSyncLivingData in project VariousOddities by Lyinginbedmon.
the class LivingData method tick.
public void tick(LivingEntity entity) {
IDefaultSpecies mobDefaults = entity instanceof IDefaultSpecies ? (IDefaultSpecies) entity : null;
World world = entity.getEntityWorld();
if (!this.initialised && (!isPlayer || ((PlayerEntity) entity).getGameProfile() != null)) {
// TODO Check default home dimension registry for creature before setting to current dim
if (mobDefaults != null) {
if (((IDefaultSpecies) entity).defaultHomeDimension() != null)
setHomeDimension(((IDefaultSpecies) entity).defaultHomeDimension());
} else
setHomeDimension(world.getDimensionKey().getLocation());
if (isPlayer) {
PlayerEntity player = (PlayerEntity) entity;
String name = player.getName().getUnformattedComponentText();
if (CreatureTypeDefaults.isTypedPatron(name)) {
setCustomTypes(CreatureTypeDefaults.getPatronTypes(name));
VariousOddities.log.info("Initialised patron " + name + " as " + EnumCreatureType.getTypes(player).toHeader().getString());
}
} else {
if (mobDefaults != null) {
if (mobDefaults.defaultSpecies() != null) {
Species defaultSpecies = SpeciesRegistry.getSpecies(mobDefaults.defaultSpecies());
if (defaultSpecies != null)
setSpecies(defaultSpecies);
}
if (!mobDefaults.defaultTemplates().isEmpty())
mobDefaults.defaultTemplates().forEach((temp) -> {
Template template = VORegistries.TEMPLATES.getOrDefault(temp, null);
if (template != null)
addTemplateInitial(template);
});
if (!mobDefaults.defaultCreatureTypes().isEmpty())
mobDefaults.defaultCreatureTypes().forEach((type) -> {
addCustomType(type);
});
if (!mobDefaults.defaultAbilities().isEmpty())
mobDefaults.defaultAbilities().forEach((ability) -> {
this.abilities.addCustomAbility(AbilityRegistry.getAbility(ability.writeAtomically(new CompoundNBT())));
});
} else {
Species guess = SpeciesRegistry.getSpecies(entity.getType().getRegistryName());
if (guess != null)
setSpecies(guess);
}
setSelectedSpecies(true);
}
this.initialised = true;
markDirty();
}
if (!ConfigVO.MOBS.selectSpeciesOnLogin.get())
setSelectedSpecies(true);
handleTypes(entity, world);
PlayerEntity player = null;
if (isPlayer)
player = (PlayerEntity) entity;
if (isPlayer)
handleHealth(player);
ActionSet actions = ActionSet.fromTypes(this.entity, this.prevTypes);
// Prevent phantoms due to sleeplessness
if (!actions.sleeps()) {
if (isPlayer && !world.isRemote) {
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
ServerStatisticsManager statManager = serverPlayer.getStats();
statManager.setValue(serverPlayer, Stats.CUSTOM.get(Stats.TIME_SINCE_REST), 0);
}
}
handleAir(actions.breathes(), entity);
if (this.bludgeoning > 0F)
if (--this.recoveryTimer <= 0)
setBludgeoning(this.bludgeoning - 1F);
if (isUnconscious() != isActuallyUnconscious()) {
if (isPlayer) {
if (isUnconscious())
PlayerData.forPlayer((PlayerEntity) entity).setBodyCondition(BodyCondition.UNCONSCIOUS);
this.isUnconscious = isUnconscious();
} else {
if (isUnconscious()) {
AbstractBody.clearNearbyAttackTargetsOf(entity);
// Spawn body
LivingEntity body = EntityBodyUnconscious.createBodyFrom(entity);
((AbstractBody) body).setPocketInventory(getPocketInventory());
if (entity.isAddedToWorld()) {
// TODO Play crit attack noise when creature is knocked unconscious
if (!world.isRemote) {
world.addEntity(body);
entity.remove();
}
}
}
this.isUnconscious = isUnconscious();
}
markDirty();
}
abilities.tick();
handleConditions();
if (this.dirty) {
if (this.entity != null && !this.entity.getEntityWorld().isRemote)
PacketHandler.sendToNearby(entity.getEntityWorld(), entity, new PacketSyncLivingData(entity.getUniqueID(), this));
this.dirty = false;
}
if (world.isRemote && --this.potionSyncTimer <= 0) {
this.potionSyncTimer = Reference.Values.TICKS_PER_MINUTE;
// TODO Ping server for visualPotion value
}
}
Aggregations