Search in sources :

Example 1 with PlayerData

use of com.lying.variousoddities.capabilities.PlayerData in project VariousOddities by Lyinginbedmon.

the class FactionReputation method resetPlayerReputation.

/**
 * Returns the given player's reputation with the given faction to its configured starting value
 * @param player
 * @param factionName
 * @return
 */
public static int resetPlayerReputation(PlayerEntity player, String factionName) {
    factionName = validateName(factionName);
    FactionManager manager = FactionManager.get(player.getEntityWorld());
    Faction faction = manager.getFaction(factionName);
    int rep = faction == null ? 0 : faction.startingRep;
    PlayerData data = PlayerData.forPlayer(player);
    if (data != null)
        data.reputation.setReputation(factionName, rep);
    return rep;
}
Also used : FactionManager(com.lying.variousoddities.world.savedata.FactionManager) PlayerData(com.lying.variousoddities.capabilities.PlayerData) Faction(com.lying.variousoddities.world.savedata.FactionManager.Faction)

Example 2 with PlayerData

use of com.lying.variousoddities.capabilities.PlayerData in project VariousOddities by Lyinginbedmon.

the class IngameGuiMixin method func_238454_b_.

@Inject(method = "func_238454_b_(Lcom/mojang/blaze3d/matrix/MatrixStack;I)V", at = @At("HEAD"), cancellable = true)
public void func_238454_b_(MatrixStack matrixStack, int xPos, final CallbackInfo ci) {
    Minecraft mc = Minecraft.getInstance();
    PlayerEntity player = mc.player;
    if (player == null)
        return;
    PlayerData data = PlayerData.forPlayer(player);
    if (data == null || PlayerData.isPlayerNormalFunction(player))
        return;
    ci.cancel();
    AbstractGui gui = (AbstractGui) (Object) this;
    ITextComponent displayText = null;
    switch(data.getBodyCondition()) {
        case DEAD:
            float progress = 1F - data.timeToRespawnable();
            mc.getProfiler().startSection("expBar");
            mc.getTextureManager().bindTexture(AbstractGui.GUI_ICONS_LOCATION);
            int k = (int) (progress * 183.0F);
            int l = this.scaledHeight - 32 + 3;
            gui.blit(matrixStack, xPos, l, 0, 64, 182, 5);
            if (k > 0)
                gui.blit(matrixStack, xPos, l, 0, 69, k, 5);
            mc.getProfiler().endSection();
            if (progress >= 1F) {
                KeyBinding inv = mc.gameSettings.keyBindInventory;
                displayText = new TranslationTextComponent("gui." + Reference.ModInfo.MOD_ID + ".dead_player_respawn", inv.func_238171_j_().getString().toUpperCase());
            }
        case UNCONSCIOUS:
            if (!LivingData.forEntity(player).isUnconscious() && data.getSoulCondition() == SoulCondition.ALIVE) {
                KeyBinding inv = mc.gameSettings.keyBindInventory;
                displayText = new TranslationTextComponent("gui." + Reference.ModInfo.MOD_ID + ".unconscious_player_awaken", inv.func_238171_j_().getString().toUpperCase());
            }
        default:
            ;
    }
    if (displayText != null) {
        String s = displayText.getString();
        int textX = (scaledWidth - getFontRenderer().getStringWidth(s)) / 2;
        int textY = this.scaledHeight - 31 - 7;
        FontRenderer fontRenderer = getFontRenderer();
        fontRenderer.drawString(matrixStack, s, (float) (textX + 1), (float) textY, 0);
        fontRenderer.drawString(matrixStack, s, (float) (textX - 1), (float) textY, 0);
        fontRenderer.drawString(matrixStack, s, (float) textX, (float) (textY + 1), 0);
        fontRenderer.drawString(matrixStack, s, (float) textX, (float) (textY - 1), 0);
        fontRenderer.drawString(matrixStack, s, (float) textX, (float) textY, -1);
    }
}
Also used : KeyBinding(net.minecraft.client.settings.KeyBinding) AbstractGui(net.minecraft.client.gui.AbstractGui) ITextComponent(net.minecraft.util.text.ITextComponent) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) FontRenderer(net.minecraft.client.gui.FontRenderer) Minecraft(net.minecraft.client.Minecraft) PlayerData(com.lying.variousoddities.capabilities.PlayerData) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with PlayerData

use of com.lying.variousoddities.capabilities.PlayerData in project VariousOddities by Lyinginbedmon.

the class MinecraftMixin method processKeyBinds.

@Inject(method = "processKeyBinds()V", at = @At("HEAD"), cancellable = true)
public void processKeyBinds(final CallbackInfo ci) {
    PlayerEntity player = ((Minecraft) (Object) this).player;
    if (player == null)
        return;
    PlayerData data = PlayerData.forPlayer(player);
    if (data == null)
        return;
    Minecraft mc = Minecraft.getInstance();
    if (PlayerData.isPlayerNormalFunction(player) || VOHelper.isCreativeOrSpectator(player))
        return;
    else
        ci.cancel();
    while (mc.gameSettings.keyBindInventory.isPressed()) {
        switch(data.getBodyCondition()) {
            case DEAD:
                // Send respawn packet if delay completed
                if (data.timeToRespawnable() == 0F)
                    PacketHandler.sendToServer(new PacketDeadDeath());
            case UNCONSCIOUS:
                // Send wakeup packet if no longer unconscious
                if (!LivingData.forEntity(player).isUnconscious() && data.getSoulCondition() == SoulCondition.ALIVE)
                    PacketHandler.sendToServer(new PacketUnconsciousAwaken());
            default:
                ;
        }
    }
    processVitalKeys(mc);
    if (this.player.isHandActive())
        this.playerController.onStoppedUsingItem(this.player);
    this.sendClickBlockToController(false);
}
Also used : PacketDeadDeath(com.lying.variousoddities.network.PacketDeadDeath) PacketUnconsciousAwaken(com.lying.variousoddities.network.PacketUnconsciousAwaken) Minecraft(net.minecraft.client.Minecraft) PlayerData(com.lying.variousoddities.capabilities.PlayerData) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with PlayerData

use of com.lying.variousoddities.capabilities.PlayerData in project VariousOddities by Lyinginbedmon.

the class NearestAttackableTargetGoalMixin method getPredicate.

private static Predicate<LivingEntity> getPredicate(LivingEntity goalOwnerIn) {
    return new Predicate<LivingEntity>() {

        public boolean test(LivingEntity target) {
            // Undead mobs do not target other undead
            if (goalOwnerIn.isNonBoss() && goalOwnerIn.isEntityUndead())
                if (target.isEntityUndead())
                    return false;
            // Mobs do not attack creatures that have mind-controlled them somehow
            LivingData mobData = LivingData.forEntity(goalOwnerIn);
            if (mobData != null && mobData.isTargetingHindered(target))
                return false;
            // Faction mobs do not attack mobs with good reputation
            if (goalOwnerIn instanceof IFactionMob) {
                FactionManager factionManager = FactionManager.get(target.getEntityWorld());
                Faction ownerFaction = factionManager.getFaction(goalOwnerIn);
                if (ownerFaction != null)
                    if (target.getType() == EntityType.PLAYER) {
                        PlayerData data = PlayerData.forPlayer((PlayerEntity) target);
                        if (data != null) {
                            int reputation = data.reputation.getReputation(ownerFaction.name);
                            if (reputation == Integer.MIN_VALUE) {
                                data.reputation.setReputation(ownerFaction.name, ownerFaction.startingRep);
                                reputation = ownerFaction.startingRep;
                            }
                            return EnumAttitude.fromRep(reputation).allowsInteraction(EnumInteraction.ATTACK);
                        }
                    } else if (target instanceof IFactionMob) {
                        Faction inputFaction = factionManager.getFaction(target);
                        if (inputFaction != null)
                            return ownerFaction.relationWith(inputFaction.name).allowsInteraction(EnumInteraction.ATTACK);
                    }
            }
            return true;
        }
    };
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) IFactionMob(com.lying.variousoddities.api.entity.IFactionMob) LivingData(com.lying.variousoddities.capabilities.LivingData) FactionManager(com.lying.variousoddities.world.savedata.FactionManager) PlayerData(com.lying.variousoddities.capabilities.PlayerData) Predicate(java.util.function.Predicate) Faction(com.lying.variousoddities.world.savedata.FactionManager.Faction) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 5 with PlayerData

use of com.lying.variousoddities.capabilities.PlayerData in project VariousOddities by Lyinginbedmon.

the class VOBusClient method noclipHideEntities.

@SuppressWarnings({ "rawtypes", "unchecked" })
@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
public static <T extends LivingEntity, M extends EntityModel<T>> void noclipHideEntities(RenderLivingEvent.Pre event) {
    LivingEntity renderTarget = event.getEntity();
    if (playerInWall()) {
        Vector3d posFeet = renderTarget.getPositionVec();
        Vector3d posEyes = posFeet.add(0D, renderTarget.getEyeHeight(), 0D);
        PlayerEntity player = mc.player;
        Vector3d posView = player.getPositionVec().add(0D, player.getEyeHeight(), 0D);
        if (posView.distanceTo(posFeet) > 8D || posView.distanceTo(posEyes) > 8D)
            event.setCanceled(true);
    }
    if (skipRenderEvent)
        skipRenderEvent = false;
    else if (renderTarget instanceof PlayerEntity) {
        PlayerData data = PlayerData.forPlayer((PlayerEntity) renderTarget);
        if (!AbilityRegistry.getAbilitiesOfType(renderTarget, AbilityPhasing.class).isEmpty() || (data != null && data.getBodyCondition() != BodyCondition.ALIVE)) {
            event.setCanceled(true);
            IRenderTypeBuffer.Impl iRenderTypeBuffer = mc.getRenderTypeBuffers().getBufferSource();
            event.getMatrixStack().push();
            skipRenderEvent = true;
            event.getRenderer().render(renderTarget, renderTarget.rotationYaw, event.getPartialRenderTick(), event.getMatrixStack(), iRenderTypeBuffer, 0xffffff);
            event.getMatrixStack().pop();
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) PlayerData(com.lying.variousoddities.capabilities.PlayerData) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

PlayerData (com.lying.variousoddities.capabilities.PlayerData)18 PlayerEntity (net.minecraft.entity.player.PlayerEntity)10 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)7 LivingData (com.lying.variousoddities.capabilities.LivingData)6 LivingEntity (net.minecraft.entity.LivingEntity)6 PacketSyncLivingData (com.lying.variousoddities.network.PacketSyncLivingData)4 FactionManager (com.lying.variousoddities.world.savedata.FactionManager)3 Faction (com.lying.variousoddities.world.savedata.FactionManager.Faction)3 ClientPlayerEntity (net.minecraft.client.entity.player.ClientPlayerEntity)3 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)3 CompoundNBT (net.minecraft.nbt.CompoundNBT)3 Inject (org.spongepowered.asm.mixin.injection.Inject)3 EntityBodyCorpse (com.lying.variousoddities.entity.EntityBodyCorpse)2 Minecraft (net.minecraft.client.Minecraft)2 World (net.minecraft.world.World)2 ServerWorld (net.minecraft.world.server.ServerWorld)2 IFactionMob (com.lying.variousoddities.api.entity.IFactionMob)1 AbilityAffectEntityEvent (com.lying.variousoddities.api.event.AbilityEvent.AbilityAffectEntityEvent)1 GetEntityTypesEvent (com.lying.variousoddities.api.event.CreatureTypeEvent.GetEntityTypesEvent)1 FireworkExplosionEvent (com.lying.variousoddities.api.event.FireworkExplosionEvent)1