Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
+Added Config Options
+Added Reset Command
+Incremented Version
  • Loading branch information
CleverNucleus committed Feb 4, 2021
1 parent 4cb97bc commit de7ba2c
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 38 deletions.
3 changes: 3 additions & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-Implement AppleSkin GUI mechanics to our overlay
-On ALT_HOLD it should display saturation
-When food item is in MAINHAND equipment slot, show percentage stat for food/saturation once item has been consumed (blinky effect)
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

mod_version=1.1.6
mod_version=1.1.7
mod_group=com.github.clevernucleus
mod_name=playerex
mod_author=CleverNucleus
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Random;

import com.github.clevernucleus.playerex.api.ExAPI;
import com.github.clevernucleus.playerex.api.attribute.IPlayerAttribute;
import com.github.clevernucleus.playerex.api.attribute.PlayerAttributes;
import com.github.clevernucleus.playerex.init.capability.AttributesCapability;
import com.github.clevernucleus.playerex.init.capability.CapabilityProvider;
Expand All @@ -19,6 +20,7 @@
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;

@Mod.EventBusSubscriber(modid = ExAPI.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class EventHandler {
Expand All @@ -40,17 +42,38 @@ private static void init(final PlayerEntity par0) {
var.add(par0, PlayerAttributes.DEXTERITY, CommonConfig.COMMON.dexterity.get().doubleValue());
var.add(par0, PlayerAttributes.INTELLIGENCE, CommonConfig.COMMON.intelligence.get().doubleValue());
var.add(par0, PlayerAttributes.LUCKINESS, CommonConfig.COMMON.luckiness.get().doubleValue());
var.add(par0, PlayerAttributes.MAX_HEALTH, -20D);
var.add(par0, PlayerAttributes.MAX_HEALTH, (CommonConfig.COMMON.maxHealth.get() ? -20D : CommonConfig.COMMON.constitution.get().doubleValue() - 20D));
var0.putBoolean("Initialised", true);
}
});
}

/** Bit of a temporary thing; we'll rewrite this nicely when we rework the system for 1.17 (or pre-1.17)*/
public static void reset(final PlayerEntity par0, final boolean par1) {
if(par0 == null) return;
if(par0.world.isRemote) return;

ExAPI.playerAttributes(par0).ifPresent(var -> {
if(par1) {
for(IPlayerAttribute v : PlayerAttributes.attributes()) {
var.forceSet(par0, v, 0);
}
}

var.add(par0, PlayerAttributes.CONSTITUTION, CommonConfig.COMMON.constitution.get().doubleValue());
var.add(par0, PlayerAttributes.STRENGTH, CommonConfig.COMMON.strength.get().doubleValue());
var.add(par0, PlayerAttributes.DEXTERITY, CommonConfig.COMMON.dexterity.get().doubleValue());
var.add(par0, PlayerAttributes.INTELLIGENCE, CommonConfig.COMMON.intelligence.get().doubleValue());
var.add(par0, PlayerAttributes.LUCKINESS, CommonConfig.COMMON.luckiness.get().doubleValue());
var.add(par0, PlayerAttributes.MAX_HEALTH, (CommonConfig.COMMON.maxHealth.get() ? -20D : CommonConfig.COMMON.constitution.get().doubleValue() - 20D));
});
}

/**
* Updates the values of the player's attributes.
* @param par0 Player instance.
*/
private static void update(PlayerEntity par0) {
public static void update(PlayerEntity par0) {
if(par0 == null) return;
if(par0.world.isRemote) return;

Expand All @@ -61,13 +84,18 @@ private static void update(PlayerEntity par0) {
* Sends packets from the server to the client to sync the client with the server.
* @param par0 Player instance.
*/
private static void sync(PlayerEntity par0) {
public static void sync(PlayerEntity par0) {
if(par0 == null) return;
if(par0.world.isRemote) return;

ExAPI.playerAttributes(par0).ifPresent(var -> ((AttributesCapability)var).send(par0));
}

@SubscribeEvent
public static void serverLoad(final FMLServerStartingEvent par0) {
ResetCommand.register(par0.getServer().getCommandManager().getDispatcher());
}

/**
* Event for attaching capabilities.
* @param par0
Expand All @@ -89,6 +117,13 @@ public static void onPlayerEntityCloned(final net.minecraftforge.event.entity.pl
PlayerEntity var1 = par0.getOriginal();

if(var0.world.isRemote) return;
if(par0.isWasDeath() && CommonConfig.COMMON.resetOnDeath.get()) {
reset(var0, false);
update(var0);
sync(var0);

return;
}

try {
ExAPI.playerAttributes(var0).ifPresent(par1 -> {
Expand Down
66 changes: 34 additions & 32 deletions src/main/java/com/github/clevernucleus/playerex/init/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.github.clevernucleus.playerex.init.capability.SyncPlayerAttributes;
import com.github.clevernucleus.playerex.init.container.PlayerAttributesContainer;
import com.github.clevernucleus.playerex.init.container.SwitchScreens;
import com.github.clevernucleus.playerex.util.CommonConfig;

import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.inventory.container.Container;
import net.minecraft.inventory.container.ContainerType;
Expand Down Expand Up @@ -76,61 +78,61 @@ public void readNBT(Capability<IPlayerAttributes> par0, IPlayerAttributes par1,
var1.add(var0, PlayerAttributes.SKILLPOINTS, var2);
});
PlayerAttributes.registerAdder(PlayerAttributes.CONSTITUTION.registryName(), (var0, var1, var2) -> {
var1.add(var0, PlayerAttributes.MAX_HEALTH, var2);
Util.add(var1, var0, PlayerAttributes.KNOCKBACK_RESISTANCE, var2 * 0.01D, 1.0D);
if(CommonConfig.COMMON.maxHealth.get()) {var1.add(var0, PlayerAttributes.MAX_HEALTH, var2);}
if(CommonConfig.COMMON.knockbackRes.get()) {Util.add(var1, var0, PlayerAttributes.KNOCKBACK_RESISTANCE, var2 * 0.01D, 1.0D);}
});
PlayerAttributes.registerAdder(PlayerAttributes.STRENGTH.registryName(), (var0, var1, var2) -> {
var1.add(var0, PlayerAttributes.HEALTH_REGEN, var2 * 0.0005D);
var1.add(var0, PlayerAttributes.MELEE_DAMAGE, var2 * 0.25D);
Util.add(var1, var0, PlayerAttributes.ARMOR, var2 * 0.25D, 100D);
if(CommonConfig.COMMON.healthRegen.get()) {var1.add(var0, PlayerAttributes.HEALTH_REGEN, var2 * 0.0005D);}
if(CommonConfig.COMMON.meleeDamage.get()) {var1.add(var0, PlayerAttributes.MELEE_DAMAGE, var2 * 0.25D);}
if(CommonConfig.COMMON.armor.get()) {Util.add(var1, var0, PlayerAttributes.ARMOR, var2 * 0.25D, 100D);}
});
PlayerAttributes.registerAdder(PlayerAttributes.DEXTERITY.registryName(), (var0, var1, var2) -> {
var1.add(var0, PlayerAttributes.RANGED_DAMAGE, var2 * 0.25D);
Util.add(var1, var0, PlayerAttributes.ATTACK_SPEED, var2 * 0.1D, 8.0D);
Util.add(var1, var0, PlayerAttributes.MOVEMENT_SPEED, var2 * 0.004D, 1.0D);
Util.add(var1, var0, PlayerAttributes.MELEE_CRIT_DAMAGE, var2 * 0.05D, 10.0D);
if(CommonConfig.COMMON.rangedDamage.get()) {var1.add(var0, PlayerAttributes.RANGED_DAMAGE, var2 * 0.25D);}
if(CommonConfig.COMMON.attackSpeed.get()) {Util.add(var1, var0, PlayerAttributes.ATTACK_SPEED, var2 * 0.1D, 8.0D);}
if(CommonConfig.COMMON.movementSpeed.get()) {Util.add(var1, var0, PlayerAttributes.MOVEMENT_SPEED, var2 * 0.004D, 1.0D);}
if(CommonConfig.COMMON.meleeCritDamage.get()) {Util.add(var1, var0, PlayerAttributes.MELEE_CRIT_DAMAGE, var2 * 0.05D, 10.0D);}
});
PlayerAttributes.registerAdder(PlayerAttributes.INTELLIGENCE.registryName(), (var0, var1, var2) -> {
Util.add(var1, var0, PlayerAttributes.HEALTH_REGEN_AMP, var2 * 0.01D, 10.0D);
Util.add(var1, var0, PlayerAttributes.RANGED_CRIT_DAMAGE, var2 * 0.05D, 10.0D);
Util.add(var1, var0, PlayerAttributes.LIFESTEAL, var2 * 0.02D, 10.0D);
if(CommonConfig.COMMON.healthRegenAmp.get()) {Util.add(var1, var0, PlayerAttributes.HEALTH_REGEN_AMP, var2 * 0.01D, 10.0D);}
if(CommonConfig.COMMON.rangedCritDamage.get()) {Util.add(var1, var0, PlayerAttributes.RANGED_CRIT_DAMAGE, var2 * 0.05D, 10.0D);}
if(CommonConfig.COMMON.lifesteal.get()) {Util.add(var1, var0, PlayerAttributes.LIFESTEAL, var2 * 0.02D, 10.0D);}
});
PlayerAttributes.registerAdder(PlayerAttributes.LUCKINESS.registryName(), (var0, var1, var2) -> {
var1.add(var0, PlayerAttributes.LUCK, var2);
Util.add(var1, var0, PlayerAttributes.MELEE_CRIT_CHANCE, var2 * 0.02D, 1.0D);
Util.add(var1, var0, PlayerAttributes.RANGED_CRIT_CHANCE, var2 * 0.02D, 1.0D);
Util.add(var1, var0, PlayerAttributes.EVASION, var2 * 0.02D, 1.0D);
if(CommonConfig.COMMON.luck.get()) {var1.add(var0, PlayerAttributes.LUCK, var2);}
if(CommonConfig.COMMON.meleeCritChance.get()) {Util.add(var1, var0, PlayerAttributes.MELEE_CRIT_CHANCE, var2 * 0.02D, 1.0D);}
if(CommonConfig.COMMON.rangedCritChance.get()) {Util.add(var1, var0, PlayerAttributes.RANGED_CRIT_CHANCE, var2 * 0.02D, 1.0D);}
if(CommonConfig.COMMON.evasion.get()) {Util.add(var1, var0, PlayerAttributes.EVASION, var2 * 0.02D, 1.0D);}
});
PlayerAttributes.registerAdder(PlayerAttributes.MAX_HEALTH.registryName(), (var0, var1, var2) -> {
if(var0.getHealth() > var0.getMaxHealth()) {
var0.setHealth(var0.getMaxHealth());
}
});
PlayerAttributes.registerModifier(PlayerAttributes.CONSTITUTION.registryName(), (var0, var1, var2) -> {
var1.apply(var0, PlayerAttributes.MAX_HEALTH, var2);
Util.apply(var1, var0, PlayerAttributes.KNOCKBACK_RESISTANCE, var2, 0.01D, 1.0D);
if(CommonConfig.COMMON.maxHealth.get()) {var1.apply(var0, PlayerAttributes.MAX_HEALTH, var2);}
if(CommonConfig.COMMON.knockbackRes.get()) {Util.apply(var1, var0, PlayerAttributes.KNOCKBACK_RESISTANCE, var2, 0.01D, 1.0D);}
});
PlayerAttributes.registerModifier(PlayerAttributes.STRENGTH.registryName(), (var0, var1, var2) -> {
Util.apply(var1, var0, PlayerAttributes.HEALTH_REGEN, var2, 0.0005D);
Util.apply(var1, var0, PlayerAttributes.MELEE_DAMAGE, var2, 0.25D);
Util.apply(var1, var0, PlayerAttributes.ARMOR, var2, 0.25D, 100D);
if(CommonConfig.COMMON.healthRegen.get()) {Util.apply(var1, var0, PlayerAttributes.HEALTH_REGEN, var2, 0.0005D);}
if(CommonConfig.COMMON.meleeDamage.get()) {Util.apply(var1, var0, PlayerAttributes.MELEE_DAMAGE, var2, 0.25D);}
if(CommonConfig.COMMON.armor.get()) {Util.apply(var1, var0, PlayerAttributes.ARMOR, var2, 0.25D, 100D);}
});
PlayerAttributes.registerModifier(PlayerAttributes.DEXTERITY.registryName(), (var0, var1, var2) -> {
Util.apply(var1, var0, PlayerAttributes.RANGED_DAMAGE, var2, 0.25D);
Util.apply(var1, var0, PlayerAttributes.ATTACK_SPEED, var2, 0.1D, 8.0D);
Util.apply(var1, var0, PlayerAttributes.MOVEMENT_SPEED, var2, 0.004D, 1.0D);
Util.apply(var1, var0, PlayerAttributes.MELEE_CRIT_DAMAGE, var2, 0.05D, 10.0D);
if(CommonConfig.COMMON.rangedDamage.get()) {Util.apply(var1, var0, PlayerAttributes.RANGED_DAMAGE, var2, 0.25D);}
if(CommonConfig.COMMON.attackSpeed.get()) {Util.apply(var1, var0, PlayerAttributes.ATTACK_SPEED, var2, 0.1D, 8.0D);}
if(CommonConfig.COMMON.movementSpeed.get()) {Util.apply(var1, var0, PlayerAttributes.MOVEMENT_SPEED, var2, 0.004D, 1.0D);}
if(CommonConfig.COMMON.meleeCritDamage.get()) {Util.apply(var1, var0, PlayerAttributes.MELEE_CRIT_DAMAGE, var2, 0.05D, 10.0D);}
});
PlayerAttributes.registerModifier(PlayerAttributes.INTELLIGENCE.registryName(), (var0, var1, var2) -> {
Util.apply(var1, var0, PlayerAttributes.HEALTH_REGEN_AMP, var2, 0.01D, 10.0D);
Util.apply(var1, var0, PlayerAttributes.RANGED_CRIT_DAMAGE, var2, 0.05D, 10.0D);
Util.apply(var1, var0, PlayerAttributes.LIFESTEAL, var2, 0.02D, 10.0D);
if(CommonConfig.COMMON.healthRegenAmp.get()) {Util.apply(var1, var0, PlayerAttributes.HEALTH_REGEN_AMP, var2, 0.01D, 10.0D);}
if(CommonConfig.COMMON.rangedCritDamage.get()) {Util.apply(var1, var0, PlayerAttributes.RANGED_CRIT_DAMAGE, var2, 0.05D, 10.0D);}
if(CommonConfig.COMMON.lifesteal.get()) {Util.apply(var1, var0, PlayerAttributes.LIFESTEAL, var2, 0.02D, 10.0D);}
});
PlayerAttributes.registerModifier(PlayerAttributes.LUCKINESS.registryName(), (var0, var1, var2) -> {
var1.apply(var0, PlayerAttributes.LUCK, var2);
Util.apply(var1, var0, PlayerAttributes.MELEE_CRIT_CHANCE, var2, 0.02D, 1.0D);
Util.apply(var1, var0, PlayerAttributes.RANGED_CRIT_CHANCE, var2, 0.02D, 1.0D);
Util.apply(var1, var0, PlayerAttributes.EVASION, var2, 0.02D, 1.0D);
if(CommonConfig.COMMON.luck.get()) {var1.apply(var0, PlayerAttributes.LUCK, var2);}
if(CommonConfig.COMMON.meleeCritChance.get()) {Util.apply(var1, var0, PlayerAttributes.MELEE_CRIT_CHANCE, var2, 0.02D, 1.0D);}
if(CommonConfig.COMMON.rangedCritChance.get()) {Util.apply(var1, var0, PlayerAttributes.RANGED_CRIT_CHANCE, var2, 0.02D, 1.0D);}
if(CommonConfig.COMMON.evasion.get()) {Util.apply(var1, var0, PlayerAttributes.EVASION, var2, 0.02D, 1.0D);}
});
PlayerAttributes.registerModifier(PlayerAttributes.MAX_HEALTH.registryName(), (var0, var1, var2) -> {
if(var0.getHealth() > var0.getMaxHealth()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.github.clevernucleus.playerex.init;

import com.github.clevernucleus.playerex.api.ExAPI;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;

import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.command.ISuggestionProvider;
import net.minecraft.command.arguments.EntityArgument;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.management.PlayerList;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TextFormatting;

public class ResetCommand {

/** Error procedure. */
private static boolean error(final CommandContext<CommandSource> par0, final PlayerEntity par1) {
if(par1.world.isRemote) return true;

PlayerList var0 = par0.getSource().getServer().getPlayerList();

if(!var0.getPlayers().contains(par1)) {
par0.getSource().sendFeedback(new StringTextComponent(TextFormatting.RED + par1.getDisplayName().toString() + TextFormatting.GRAY + " does not exist!"), true);

return true;
}

return false;
}

/** A partially formed entitled command. */
private static int run(CommandContext<CommandSource> par0) throws CommandSyntaxException {
par0.getSource().sendFeedback(new StringTextComponent(TextFormatting.RED + "/playerex player reset"), true);

return 1;
}

private static int reset(CommandContext<CommandSource> par0, PlayerEntity par1) throws CommandSyntaxException {
if(error(par0, par1)) return 1;

EventHandler.reset(par1, true);
EventHandler.update(par1);
EventHandler.sync(par1);

return 1;
}

/**
* Register the command(s) to the game.
* @param par0
*/
public static void register(CommandDispatcher<CommandSource> par0) {
par0.register(Commands.literal(ExAPI.MODID)
.requires(var -> var.hasPermissionLevel(2))
.executes(ResetCommand::run).then(Commands.argument("player", EntityArgument.player()).suggests((var0, var1) -> {
PlayerList var2 = var0.getSource().getServer().getPlayerList();

return ISuggestionProvider.suggest(var2.getPlayers().stream().map(var3 -> var3.getGameProfile().getName()), var1);
}).then(Commands.literal("reset").executes(var -> reset(var, EntityArgument.getPlayer(var, "player"))))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.github.clevernucleus.playerex.api.ExAPI;

import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.ForgeConfigSpec.BooleanValue;
import net.minecraftforge.common.ForgeConfigSpec.DoubleValue;
import net.minecraftforge.common.ForgeConfigSpec.IntValue;

Expand Down Expand Up @@ -32,6 +33,10 @@ public static class Common {
public final IntValue constitution, strength, dexterity, intelligence, luckiness;
/** expCoeff parameters. */
public final DoubleValue offset, scale;
/** reset attributes on death */
public final BooleanValue resetOnDeath;

public final BooleanValue maxHealth, knockbackRes, healthRegen, meleeDamage, armor, rangedDamage, attackSpeed, movementSpeed, meleeCritDamage, healthRegenAmp, rangedCritDamage, lifesteal, luck, meleeCritChance, rangedCritChance, evasion;

public Common(ForgeConfigSpec.Builder par0) {
par0.comment("These only have an affect when a player is first joining the world.").push("attributes");
Expand Down Expand Up @@ -62,6 +67,35 @@ public Common(ForgeConfigSpec.Builder par0) {
.worldRestart()
.defineInRange("luckiness", 0, 0, 20);

par0.pop();
par0.comment("These are adder/modifier functions implemented by default. This is a stopgap config option to disable some until datadriven mechanics are released.").push("functions");
par0.comment("If you want to add custom attributes, use the API.");

this.maxHealth = par0.comment("Added on Constitution").worldRestart().define("addMaxHealth", true);
this.knockbackRes = par0.comment("Added on Constitution").worldRestart().define("addKnockbackRes", true);
this.healthRegen = par0.comment("Added on Strength").worldRestart().define("addHealthRegen", true);
this.meleeDamage = par0.comment("Added on Strength").worldRestart().define("addMeleeDamage", true);
this.armor = par0.comment("Added on Strength").worldRestart().define("addArmor", true);
this.rangedDamage = par0.comment("Added on Dexterity").worldRestart().define("addRangedDamage", true);
this.attackSpeed = par0.comment("Added on Dexterity").worldRestart().define("addAttackSpeed", true);
this.movementSpeed = par0.comment("Added on Dexterity").worldRestart().define("addMovementSpeed", true);
this.meleeCritDamage = par0.comment("Added on Dexterity").worldRestart().define("addMeleeCritDamage", true);
this.healthRegenAmp = par0.comment("Added on Intelligence").worldRestart().define("addHealthRegenAmp", true);
this.rangedCritDamage = par0.comment("Added on Intelligence").worldRestart().define("addRangedCritDamage", true);
this.lifesteal = par0.comment("Added on Intelligence").worldRestart().define("addLifesteal", true);
this.luck = par0.comment("Added on Luckiness").worldRestart().define("addLuck", true);
this.meleeCritChance = par0.comment("Added on Luckiness").worldRestart().define("addMeleeCritChance", true);
this.rangedCritChance = par0.comment("Added on Luckiness").worldRestart().define("addRangedCritChance", true);
this.evasion = par0.comment("Added on Luckiness").worldRestart().define("addEvasion", true);

par0.pop();
par0.push("misc");

this.resetOnDeath = par0
.comment("If true, resets all attributes to their defaults on death.")
.worldRestart()
.define("resetOnDeath", false);

par0.pop();
par0.push("expcoeff");

Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ license="MIT License"

[[mods]]
modId="playerex"
version="1.1.6"
version="1.1.7"
displayName="Player Ex"
displayURL="https://github.com/CleverNucleus/PlayerEx"
logoFile="logo.png"
credits="CleverNucleus: Code and major texturer."
credits="CleverNucleus: Code and major texturer; sky_bai: simplified chinese translation (thanks!)"
authors="CleverNucleus"

description='''
Expand Down

0 comments on commit de7ba2c

Please sign in to comment.