Skip to content

Commit

Permalink
Added Magic Amp and Step height
Browse files Browse the repository at this point in the history
  • Loading branch information
CleverNucleus committed Jun 29, 2021
1 parent 6b4b640 commit cc61be6
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public final class PlayerAttributes {
public static final IAttribute RANGED_CRIT_DAMAGE = find(new Identifier(ExAPI.MODID, "ranged_crit_damage"));
/** PlayerEx ranged crit chance */
public static final IAttribute RANGED_CRIT_CHANCE = find(new Identifier(ExAPI.MODID, "ranged_crit_chance"));
/** PlayerEx magic damage amplification */
public static final IAttribute MAGIC_AMPLIFICATION = find(new Identifier(ExAPI.MODID, "magic_amplification"));
/** Jar-in-jar step-height-entity-attribute step height */
public static final IAttribute STEP_HEIGHT = find(new Identifier("stepheightentityattribute", "stepheight"));

/**
* @param keyIn Player Attribute key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ private String reach() {
return text.getString() + ": " + value(value) + suffix;
}

private String magicAmp() {
IPlayerAttribute attribute = PlayerAttributes.MAGIC_AMPLIFICATION.get();
Text text = new TranslatableText("gui.playerex.text.magic_amp");
boolean percent = attribute.hasProperty(AttributeProperties.PROPERTY_PERCENT);
float value = (float)Maths.shownValue(attribute, this.data.get(attribute));
String suffix = percent ? "%" : "";

return text.getString() + ": " + value(value) + suffix;
}

private String crit(final IPlayerAttribute attribute) {
String key = attribute.translationKey();
String type = key.substring(key.length() - 11);
Expand Down Expand Up @@ -191,6 +201,10 @@ private void renderTooltips(MatrixStack matrices, int mouseX, int mouseY, float
if(this.isMouseOver((this.x + 108), (this.y + 103), this.textRenderer.getWidth(this.reach()) * s, 7, mouseX, mouseY)) {
this.renderTooltip(matrices, (new TranslatableText("gui.playerex.tooltip.attack_range", this.reachTT())).formatted(Formatting.GRAY), mouseX, mouseY);
}

if(this.isMouseOver((this.x + 108), (this.y + 114), this.textRenderer.getWidth(this.magicAmp()) * s, 7, mouseX, mouseY)) {
this.renderTooltip(matrices, (new TranslatableText("gui.playerex.tooltip.magic_amp")).formatted(Formatting.GRAY), mouseX, mouseY);
}
}

@Override
Expand All @@ -216,6 +230,7 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
this.textRenderer.draw(matrices, this.crit(PlayerAttributes.RANGED_CRIT_CHANCE.get()), (this.x + 96) / s, (this.y + 59) / s, 4210752);
this.textRenderer.draw(matrices, this.display(PlayerAttributes.LIFESTEAL.get()), (this.x + 108) / s, (this.y + 92) / s, 4210752);
this.textRenderer.draw(matrices, this.reach(), (this.x + 108) / s, (this.y + 103) / s, 4210752);
this.textRenderer.draw(matrices, this.magicAmp(), (this.x + 108) / s, (this.y + 114) / s, 4210752);

GlStateManager.popMatrix();

Expand All @@ -231,6 +246,7 @@ public void drawBackground(MatrixStack matrices, float delta, int mouseX, int mo
this.drawTexture(matrices, this.x + 96, this.y + 24, 235, 18, 9, 9);
this.drawTexture(matrices, this.x + 96, this.y + 90, 244, 18, 9, 9);
this.drawTexture(matrices, this.x + 96, this.y + 101, 226, 27, 9, 9);
this.drawTexture(matrices, this.x + 96, this.y + 112, 235, 27, 9, 9);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.PersistentProjectileEntity;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.entity.projectile.thrown.PotionEntity;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayNetworkHandler;
Expand Down Expand Up @@ -129,6 +130,7 @@ public static boolean onDamage(LivingEntity entity, DamageSource source, float a
} else if(source.isFire()) {
mult = (float)data.get(PlayerAttributes.FIRE_RESISTANCE.get());
} else if(source.getMagic()) {
System.out.println("Potion resist");
mult = (float)data.get(PlayerAttributes.MAGIC_RESISTANCE.get());
} else if(source.isProjectile()) {
float evasion = (float)data.get(PlayerAttributes.EVASION.get());
Expand All @@ -143,9 +145,29 @@ public static boolean onDamage(LivingEntity entity, DamageSource source, float a
if(source.getSource() instanceof PlayerEntity) {
PlayerEntity player = (PlayerEntity)source.getSource();
AttributeData data = ExAPI.DATA.get(player);
float lifesteal = (float)data.get(PlayerAttributes.LIFESTEAL.get());

player.heal(amount * lifesteal);
if(source.getMagic()) {
float magicAmp = (float)data.get(PlayerAttributes.MAGIC_AMPLIFICATION.get());

amount = amount * (1.0F + magicAmp);
} else {
float lifesteal = (float)data.get(PlayerAttributes.LIFESTEAL.get());

player.heal(amount * lifesteal);
}
} else if(source.getSource() instanceof PotionEntity) {
PotionEntity potion = (PotionEntity)source.getSource();

if(potion.getOwner() instanceof PlayerEntity) {
PlayerEntity player = (PlayerEntity)potion.getOwner();
AttributeData data = ExAPI.DATA.get(player);

if(source.getMagic()) {
float magicAmp = (float)data.get(PlayerAttributes.MAGIC_AMPLIFICATION.get());

amount = amount * (1.0F + magicAmp);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
package com.github.clevernucleus.playerex.mixin.client;

import java.util.Iterator;
import java.util.Map.Entry;
import java.util.UUID;

import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

import com.github.clevernucleus.playerex.api.ExAPI;
import com.github.clevernucleus.playerex.api.PlayerAttributes;
import com.github.clevernucleus.playerex.api.attribute.AttributeData;
import com.google.common.collect.Multimap;

import net.minecraft.client.item.TooltipContext;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityGroup;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;

@Mixin(ItemStack.class)
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/assets/playerex/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"gui.playerex.text.knockback_resistance": "Knockback Res.",
"gui.playerex.text.ranged_damage": "Damage",
"gui.playerex.text.attack_range": "Attack Ran.",
"gui.playerex.text.magic_amp": "Magic Amp.",
"gui.playerex.tooltip.level_up": "Level Up (%s)",
"gui.playerex.tooltip.skill": "Skill ",
"gui.playerex.tooltip.refund": "Refund ",
Expand Down Expand Up @@ -76,6 +77,7 @@
"gui.playerex.tooltip.ranged_crit_chance": "The chance for a ranged attack to be a critical hit.",
"gui.playerex.tooltip.lifesteal": "A percentage of melee attack damage dealt is healed.",
"gui.playerex.tooltip.attack_range": "Attack Range: %s blocks",
"gui.playerex.tooltip.magic_amp": "Amplifies most magic damage.",
"command.playerex.modifier.already_present": "Modifier already present!",
"command.playerex.modifier.error": "Modifier not present!",
"command.playerex.modifier.get": "Modifier value: %s",
Expand Down Expand Up @@ -112,5 +114,6 @@
"attribute.name.playerex.evasion": "Evasion",
"attribute.name.playerex.ranged_damage": "Ranged Damage",
"attribute.name.playerex.ranged_crit_damage": "Ranged Crit Damage",
"attribute.name.playerex.ranged_crit_chance": "Ranged Crit Chance"
"attribute.name.playerex.ranged_crit_chance": "Ranged Crit Chance",
"attribute.name.playerex.magic_amplification": "Magic Amplification"
}
Binary file modified src/main/resources/assets/playerex/textures/gui/gui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/main/resources/data/playerex/attributes/intelligence.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"attribute": "playerex:wither_resistance",
"type": "DIMINISHING",
"multiplier": 0.01
},
{
"attribute": "playerex:magic_amplification",
"type": "DIMINISHING",
"multiplier": 0.05
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"type": "GAME",
"uuid": "26bcb796-9214-4c10-9bad-28e50980ec21",
"defaultValue": 0.0,
"minValue": 0.0,
"maxValue": 10.0,
"translationKey": "attribute.name.playerex.magic_amplification",
"properties": {
"percent": 100.0,
"weight": 0.4,
"minroll": 0.01,
"maxroll": 0.25
},
"functions": []
}

0 comments on commit cc61be6

Please sign in to comment.