use of net.minecraft.stats.StatisticsManager in project AstralSorcery by HellFirePvP.
the class RootVicio method onPlayerTick.
@Override
public void onPlayerTick(PlayerEntity player, LogicalSide side) {
if (!side.isServer() || !(player instanceof ServerPlayerEntity)) {
return;
}
UUID uuid = player.getUniqueID();
ServerPlayerEntity sPlayer = (ServerPlayerEntity) player;
PlayerProgress prog = ResearchHelper.getProgress(player, side);
StatisticsManager mgr = sPlayer.getStats();
int walked = mgr.getValue(Stats.CUSTOM.get(Stats.WALK_ONE_CM));
int sprint = mgr.getValue(Stats.CUSTOM.get(Stats.SPRINT_ONE_CM));
int flown = mgr.getValue(Stats.CUSTOM.get(Stats.FLY_ONE_CM));
int elytra = mgr.getValue(Stats.CUSTOM.get(Stats.AVIATE_ONE_CM));
int swam = mgr.getValue(Stats.CUSTOM.get(Stats.SWIM_ONE_CM));
int lastWalked = this.moveTrackMap.computeIfAbsent(Stats.WALK_ONE_CM, s -> new HashMap<>()).computeIfAbsent(uuid, u -> walked);
int lastSprint = this.moveTrackMap.computeIfAbsent(Stats.SPRINT_ONE_CM, s -> new HashMap<>()).computeIfAbsent(uuid, u -> sprint);
int lastFly = this.moveTrackMap.computeIfAbsent(Stats.FLY_ONE_CM, s -> new HashMap<>()).computeIfAbsent(uuid, u -> flown);
int lastElytra = this.moveTrackMap.computeIfAbsent(Stats.AVIATE_ONE_CM, s -> new HashMap<>()).computeIfAbsent(uuid, u -> elytra);
int lastSwam = this.moveTrackMap.computeIfAbsent(Stats.SWIM_ONE_CM, s -> new HashMap<>()).computeIfAbsent(uuid, u -> swam);
float added = 0;
if (walked > lastWalked) {
added += Math.min(walked - lastWalked, 500F);
if (added >= 500F) {
added = 500F;
}
added *= 0.9F;
this.moveTrackMap.get(Stats.WALK_ONE_CM).put(uuid, walked);
}
if (sprint > lastSprint) {
added += Math.min(sprint - lastSprint, 500F);
if (added >= 500F) {
added = 500F;
}
added *= 0.8F;
this.moveTrackMap.get(Stats.SPRINT_ONE_CM).put(uuid, sprint);
}
if (flown > lastFly) {
added += Math.min(flown - lastFly, 500F);
added *= 0.3F;
this.moveTrackMap.get(Stats.FLY_ONE_CM).put(uuid, flown);
}
if (elytra > lastElytra) {
added += Math.min(elytra - lastElytra, 500F);
added *= 0.55F;
this.moveTrackMap.get(Stats.AVIATE_ONE_CM).put(uuid, elytra);
}
if (swam > lastSwam) {
added += Math.min(swam - lastSwam, 500F);
added *= 1.2F;
this.moveTrackMap.get(Stats.SWIM_ONE_CM).put(uuid, swam);
}
if (added > 0) {
added *= 0.02F;
added *= this.getExpMultiplier();
added *= this.getDiminishingReturns(player);
added *= PerkAttributeHelper.getOrCreateMap(player, side).getModifier(player, prog, PerkAttributeTypesAS.ATTR_TYPE_INC_PERK_EFFECT);
added *= PerkAttributeHelper.getOrCreateMap(player, side).getModifier(player, prog, PerkAttributeTypesAS.ATTR_TYPE_INC_PERK_EXP);
added = AttributeEvent.postProcessModded(player, PerkAttributeTypesAS.ATTR_TYPE_INC_PERK_EXP, added);
ResearchManager.modifyExp(player, added);
}
}
use of net.minecraft.stats.StatisticsManager in project upgrade-aquatic by team-abnormals.
the class InsomniaEffect method performEffect.
@Override
public void performEffect(LivingEntity entity, int amplifier) {
if (entity instanceof ServerPlayerEntity) {
ServerPlayerEntity playerMP = (ServerPlayerEntity) entity;
StatisticsManager statisticsManager = playerMP.getStats();
statisticsManager.increment(playerMP, Stats.CUSTOM.get(Stats.TIME_SINCE_REST), (24000 * (amplifier + 1)));
} else if (entity instanceof PhantomEntity) {
FlareEntity flare = UAEntities.FLARE.get().create(entity.world);
flare.setLocationAndAngles(entity.getPosX(), entity.getPosY(), entity.getPosZ(), entity.rotationYaw, entity.rotationPitch);
flare.setNoAI(((MobEntity) entity).isAIDisabled());
if (entity.hasCustomName()) {
flare.setCustomName(entity.getCustomName());
flare.setCustomNameVisible(entity.isCustomNameVisible());
}
flare.setHealth(entity.getHealth());
if (flare.getHealth() > 0) {
entity.world.addEntity(flare);
entity.remove(true);
}
PlayerEntity player = entity.getEntityWorld().getClosestPlayer(entity, 11);
if (player instanceof ServerPlayerEntity && player.isAlive()) {
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
if (!entity.world.isRemote()) {
UACriteriaTriggers.CONVERT_PHANTOM.trigger(serverPlayer);
}
}
} else if (entity instanceof FlareEntity) {
entity.attackEntityFrom(DamageSource.MAGIC, Float.MAX_VALUE);
}
}
use of net.minecraft.stats.StatisticsManager in project upgrade-aquatic by team-abnormals.
the class EntityEvents method onEntityUpdate.
@SubscribeEvent
public static void onEntityUpdate(LivingUpdateEvent event) {
LivingEntity entity = event.getEntityLiving();
if (entity instanceof PhantomEntity) {
if (((PhantomEntity) entity).getAttackTarget() instanceof ServerPlayerEntity) {
ServerPlayerEntity playerMP = (ServerPlayerEntity) ((PhantomEntity) entity).getAttackTarget();
StatisticsManager statisticsManager = playerMP.getStats();
if (statisticsManager.getValue(Stats.CUSTOM.get(Stats.TIME_SINCE_REST)) < 72000) {
((PhantomEntity) entity).setAttackTarget(null);
}
}
}
}
use of net.minecraft.stats.StatisticsManager in project upgrade-aquatic by team-abnormals.
the class EntityEvents method onPlayerTick.
@SubscribeEvent
public static void onPlayerTick(PlayerTickEvent event) {
PlayerEntity player = event.player;
ItemStack headSlotStack = player.getItemStackFromSlot(EquipmentSlotType.HEAD);
if (!event.player.world.isRemote && event.player.world.getGameTime() % 5 == 0 && event.player instanceof ServerPlayerEntity) {
ServerPlayerEntity sPlayer = (ServerPlayerEntity) event.player;
StatisticsManager statisticsManager = sPlayer.getStats();
Object2IntMap<Stat<?>> object2intmap = new Object2IntOpenHashMap<>();
object2intmap.put(Stats.CUSTOM.get(Stats.TIME_SINCE_REST), statisticsManager.getValue(Stats.CUSTOM.get(Stats.TIME_SINCE_REST)));
sPlayer.connection.sendPacket(new SStatisticsPacket(object2intmap));
}
if (player.isServerWorld() && !headSlotStack.isEmpty() && headSlotStack.getItem() == Items.TURTLE_HELMET) {
int timeTillDamage = EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, headSlotStack) > 0 ? 40 * (1 + EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, headSlotStack) / 2) : 40;
if (player.areEyesInFluid(FluidTags.WATER)) {
player.addPotionEffect(new EffectInstance(Effects.WATER_BREATHING, 210));
if (player.world.getGameTime() % timeTillDamage == 0) {
headSlotStack.damageItem(1, player, (p_213341_0_) -> {
p_213341_0_.sendBreakAnimation(EquipmentSlotType.HEAD);
});
}
}
}
}
use of net.minecraft.stats.StatisticsManager in project CumServerPro by MCUmbrella.
the class Minecraft method setDimensionAndSpawnPlayer.
public void setDimensionAndSpawnPlayer(int dimension) {
this.world.setInitialSpawnLocation();
this.world.removeAllEntities();
int i = 0;
String s = null;
if (this.player != null) {
i = this.player.getEntityId();
this.world.removeEntity(this.player);
s = this.player.getServerBrand();
}
this.renderViewEntity = null;
EntityPlayerSP entityplayersp = this.player;
this.player = this.playerController.createPlayer(this.world, this.player == null ? new StatisticsManager() : this.player.getStatFileWriter(), this.player == null ? new RecipeBook() : this.player.getRecipeBook());
this.player.getDataManager().setEntryValues(entityplayersp.getDataManager().getAll());
// Forge: fix MC-10657
this.player.updateSyncFields(entityplayersp);
this.player.dimension = dimension;
this.renderViewEntity = this.player;
this.player.preparePlayerToSpawn();
this.player.setServerBrand(s);
this.world.spawnEntity(this.player);
this.playerController.flipPlayer(this.player);
this.player.movementInput = new MovementInputFromOptions(this.gameSettings);
this.player.setEntityId(i);
this.playerController.setPlayerCapabilities(this.player);
this.player.setReducedDebug(entityplayersp.hasReducedDebug());
if (this.currentScreen instanceof GuiGameOver) {
this.displayGuiScreen((GuiScreen) null);
}
}
Aggregations