use of com.lying.variousoddities.entity.AbstractBody in project VariousOddities by Lyinginbedmon.
the class ContainerPlayerBody method fromNetwork.
public static ContainerPlayerBody fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
PlayerEntity player = inv.player;
double range = player.getAttributeValue(ForgeMod.REACH_DISTANCE.get());
Vector3d eyeStart = player.getEyePosition(0F);
Vector3d eyeEnd = eyeStart.add(player.getLook(0F).mul(range, range, range));
AbstractBody likelyBody = null;
double minDist = Double.MAX_VALUE;
for (AbstractBody body : player.getEntityWorld().getEntitiesWithinAABB(AbstractBody.class, player.getBoundingBox().grow(range))) {
double dist = body.getDistance(player);
if (body.getBoundingBox().intersects(eyeStart, eyeEnd))
if (dist < minDist) {
likelyBody = body;
minDist = dist;
}
}
if (likelyBody != null && likelyBody.isPlayer() && likelyBody.getSoul() != null)
return new ContainerPlayerBody(windowId, inv, ((PlayerEntity) likelyBody.getSoul()).inventory, likelyBody);
return null;
}
use of com.lying.variousoddities.entity.AbstractBody 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
}
}
use of com.lying.variousoddities.entity.AbstractBody in project VariousOddities by Lyinginbedmon.
the class ContainerBody method fromNetwork.
public static ContainerBody fromNetwork(int windowId, PlayerInventory inv, PacketBuffer buf) {
PlayerEntity player = inv.player;
double range = player.getAttributeValue(ForgeMod.REACH_DISTANCE.get());
Vector3d eyeStart = player.getEyePosition(0F);
Vector3d eyeEnd = eyeStart.add(player.getLook(0F).mul(range, range, range));
AbstractBody likelyBody = null;
double minDist = Double.MAX_VALUE;
for (AbstractBody body : player.getEntityWorld().getEntitiesWithinAABB(AbstractBody.class, player.getBoundingBox().grow(range))) {
double dist = body.getDistance(player);
if (body.getBoundingBox().intersects(eyeStart, eyeEnd))
if (dist < minDist) {
likelyBody = body;
minDist = dist;
}
}
if (likelyBody != null)
return new ContainerBody(windowId, inv, likelyBody.getInventory(), likelyBody);
return null;
}
Aggregations