Search in sources :

Example 6 with StatisticsManager

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);
    }
}
Also used : ResearchManager(hellfirepvp.astralsorcery.common.data.research.ResearchManager) ResearchHelper(hellfirepvp.astralsorcery.common.data.research.ResearchHelper) PerkAttributeHelper(hellfirepvp.astralsorcery.common.perk.PerkAttributeHelper) PlayerEntity(net.minecraft.entity.player.PlayerEntity) HashMap(java.util.HashMap) UUID(java.util.UUID) ConstellationsAS(hellfirepvp.astralsorcery.common.lib.ConstellationsAS) PlayerTickPerk(hellfirepvp.astralsorcery.common.perk.tick.PlayerTickPerk) PlayerProgress(hellfirepvp.astralsorcery.common.data.research.PlayerProgress) RootPerk(hellfirepvp.astralsorcery.common.perk.node.RootPerk) StatisticsManager(net.minecraft.stats.StatisticsManager) AttributeEvent(hellfirepvp.astralsorcery.common.event.AttributeEvent) Map(java.util.Map) ResourceLocation(net.minecraft.util.ResourceLocation) Stats(net.minecraft.stats.Stats) PerkAttributeTypesAS(hellfirepvp.astralsorcery.common.lib.PerkAttributeTypesAS) Nonnull(javax.annotation.Nonnull) DiminishingMultiplier(hellfirepvp.astralsorcery.common.util.DiminishingMultiplier) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) LogicalSide(net.minecraftforge.fml.LogicalSide) StatisticsManager(net.minecraft.stats.StatisticsManager) HashMap(java.util.HashMap) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) UUID(java.util.UUID) PlayerProgress(hellfirepvp.astralsorcery.common.data.research.PlayerProgress)

Example 7 with StatisticsManager

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);
    }
}
Also used : FlareEntity(com.minecraftabnormals.upgrade_aquatic.common.entities.FlareEntity) PhantomEntity(net.minecraft.entity.monster.PhantomEntity) StatisticsManager(net.minecraft.stats.StatisticsManager) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) MobEntity(net.minecraft.entity.MobEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 8 with StatisticsManager

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);
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) PhantomEntity(net.minecraft.entity.monster.PhantomEntity) StatisticsManager(net.minecraft.stats.StatisticsManager) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 9 with StatisticsManager

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);
                });
            }
        }
    }
}
Also used : SStatisticsPacket(net.minecraft.network.play.server.SStatisticsPacket) StatisticsManager(net.minecraft.stats.StatisticsManager) Stat(net.minecraft.stats.Stat) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Object2IntOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap) ItemStack(net.minecraft.item.ItemStack) EffectInstance(net.minecraft.potion.EffectInstance) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 10 with StatisticsManager

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);
    }
}
Also used : RecipeBook(net.minecraft.stats.RecipeBook) StatisticsManager(net.minecraft.stats.StatisticsManager) GuiGameOver(net.minecraft.client.gui.GuiGameOver) MovementInputFromOptions(net.minecraft.util.MovementInputFromOptions) TextComponentString(net.minecraft.util.text.TextComponentString) NBTTagString(net.minecraft.nbt.NBTTagString) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP)

Aggregations

StatisticsManager (net.minecraft.stats.StatisticsManager)10 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)5 MovementInputFromOptions (net.minecraft.util.MovementInputFromOptions)4 PhantomEntity (net.minecraft.entity.monster.PhantomEntity)3 PlayerEntity (net.minecraft.entity.player.PlayerEntity)3 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)3 FlareEntity (com.minecraftabnormals.upgrade_aquatic.common.entities.FlareEntity)2 AuthenticationService (com.mojang.authlib.AuthenticationService)2 GameProfileRepository (com.mojang.authlib.GameProfileRepository)2 MinecraftSessionService (com.mojang.authlib.minecraft.MinecraftSessionService)2 YggdrasilAuthenticationService (com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService)2 File (java.io.File)2 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)2 GuiGameOver (net.minecraft.client.gui.GuiGameOver)2 NetHandlerPlayClient (net.minecraft.client.network.NetHandlerPlayClient)2 RecipeBookClient (net.minecraft.client.util.RecipeBookClient)2 NBTTagString (net.minecraft.nbt.NBTTagString)2 PlayerProfileCache (net.minecraft.server.management.PlayerProfileCache)2 RecipeBook (net.minecraft.stats.RecipeBook)2 ResourceLocation (net.minecraft.util.ResourceLocation)2