use of net.minecraft.world.entity.ai.attributes.AttributeInstance in project MinecraftForge by MinecraftForge.
the class GravityAttributeTest method worldTick.
@SubscribeEvent
public void worldTick(TickEvent.WorldTickEvent event) {
if (!event.world.isClientSide) {
if (ticks++ > 60) {
ticks = 0;
Level w = event.world;
List<LivingEntity> list;
if (w.isClientSide) {
ClientLevel cw = (ClientLevel) w;
list = new ArrayList<>(100);
for (Entity e : cw.entitiesForRendering()) {
if (e.isAlive() && e instanceof LivingEntity)
list.add((LivingEntity) e);
}
} else {
ServerLevel sw = (ServerLevel) w;
Stream<LivingEntity> s = StreamSupport.stream(sw.getEntities().getAll().spliterator(), false).filter(Entity::isAlive).filter(e -> e instanceof LivingEntity).map(e -> (LivingEntity) e);
list = s.collect(Collectors.toList());
}
for (LivingEntity liv : list) {
AttributeInstance grav = liv.getAttribute(ForgeMod.ENTITY_GRAVITY.get());
boolean inPlains = liv.level.getBiome(liv.blockPosition()).getBiomeCategory() == BiomeCategory.PLAINS;
if (inPlains && !grav.hasModifier(REDUCED_GRAVITY)) {
logger.info("Granted low gravity to Entity: {}", liv);
grav.addTransientModifier(REDUCED_GRAVITY);
} else if (!inPlains && grav.hasModifier(REDUCED_GRAVITY)) {
logger.info("Removed low gravity from Entity: {}", liv);
grav.removeModifier(REDUCED_GRAVITY);
}
}
}
}
}
use of net.minecraft.world.entity.ai.attributes.AttributeInstance in project MyPet by xXKeyleXx.
the class FollowOwner method applyWalkSpeed.
private void applyWalkSpeed() {
float walkSpeed = owner.getAbilities().walkingSpeed;
if (owner.getAbilities().flying) {
// make the pet faster when the player is flying
walkSpeed += owner.getAbilities().flyingSpeed;
} else if (owner.isSprinting()) {
// make the pet faster when the player is sprinting
if (owner.getAttributes().getInstance(Attributes.MOVEMENT_SPEED) != null) {
walkSpeed += owner.getAttributes().getInstance(Attributes.MOVEMENT_SPEED).getValue();
}
} else if (owner.isPassenger() && owner.getVehicle() instanceof LivingEntity) {
// adjust the speed to the pet can catch up with the vehicle the player is in
AttributeInstance vehicleSpeedAttribute = ((LivingEntity) owner.getVehicle()).getAttributes().getInstance(Attributes.MOVEMENT_SPEED);
if (vehicleSpeedAttribute != null) {
walkSpeed = (float) vehicleSpeedAttribute.getValue();
}
} else if (owner.hasEffect(MobEffects.MOVEMENT_SPEED)) {
// make the pet faster when the player is has the SPEED effect
walkSpeed += owner.getEffect(MobEffects.MOVEMENT_SPEED).getAmplifier() * 0.2 * walkSpeed;
}
// make aquatic pets faster - swimming is hard
if (this.petEntity.isInWaterOrBubble() && this.petEntity.getNavigation() instanceof MyAquaticPetPathNavigation) {
walkSpeed += 0.6f;
if (owner.isSwimming()) {
walkSpeed -= 0.035f;
}
if (owner.hasEffect(MobEffects.DOLPHINS_GRACE)) {
walkSpeed += 0.08f;
}
}
// make the pet a little bit faster than the player so it can catch up
walkSpeed += 0.07f;
nav.getParameters().addSpeedModifier("FollowOwner", walkSpeed);
}
use of net.minecraft.world.entity.ai.attributes.AttributeInstance in project MyPet by xXKeyleXx.
the class FollowOwner method applyWalkSpeed.
private void applyWalkSpeed() {
float walkSpeed = owner.getAbilities().walkingSpeed;
if (owner.getAbilities().flying) {
// make the pet faster when the player is flying
walkSpeed += owner.getAbilities().flyingSpeed;
} else if (owner.isSprinting()) {
// make the pet faster when the player is sprinting
if (owner.getAttributes().getInstance(Attributes.MOVEMENT_SPEED) != null) {
walkSpeed += owner.getAttributes().getInstance(Attributes.MOVEMENT_SPEED).getValue();
}
} else if (owner.isPassenger() && owner.getVehicle() instanceof LivingEntity) {
// adjust the speed to the pet can catch up with the vehicle the player is in
AttributeInstance vehicleSpeedAttribute = ((LivingEntity) owner.getVehicle()).getAttributes().getInstance(Attributes.MOVEMENT_SPEED);
if (vehicleSpeedAttribute != null) {
walkSpeed = (float) vehicleSpeedAttribute.getValue();
}
} else if (owner.hasEffect(MobEffects.MOVEMENT_SPEED)) {
// make the pet faster when the player is has the SPEED effect
walkSpeed += owner.getEffect(MobEffects.MOVEMENT_SPEED).getAmplifier() * 0.2 * walkSpeed;
}
// make aquatic pets faster - swimming is hard
if (this.petEntity.isInWaterOrBubble() && this.petEntity.getNavigation() instanceof MyAquaticPetPathNavigation) {
walkSpeed += 0.6f;
if (owner.isSwimming()) {
walkSpeed -= 0.035f;
}
if (owner.hasEffect(MobEffects.DOLPHINS_GRACE)) {
walkSpeed += 0.08f;
}
}
// make the pet a little bit faster than the player so it can catch up
walkSpeed += 0.07f;
nav.getParameters().addSpeedModifier("FollowOwner", walkSpeed);
}
Aggregations