Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Fix Death Reset
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeGrahamLandry committed Jul 7, 2022
1 parent b1d215d commit 67f660d
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 28 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ The content added by this mod is split into two distinct categories:

- In game content, which includes a gui, optional survival HUD and levelling attributes such as maximum health and armour.
- API system, which includes the expanded attributes system, server-client syncing and development options that allow Modders to add their own attributes, change default attributes and add tooltips.

For a comprehensive breakdown of in game content, see the [CurseForge mod page](https://www.curseforge.com/minecraft/mc-mods/player-ex). For Devs who want to use the API, please see the [Github wiki](https://github.com/CleverNucleus/PlayerEx/wiki).
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ minecraft {
}

dependencies {
minecraft 'net.minecraftforge:forge:1.18.2-40.1.20'
minecraft 'net.minecraftforge:forge:1.18.2-40.1.0'
}

repositories {
Expand Down
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.8
mod_version=1.3.2
mod_group=com.github.clevernucleus
mod_name=playerex
mod_author=CleverNucleus
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.clevernucleus.playerex.api.ExAPI;
import com.github.clevernucleus.playerex.api.attribute.IPlayerAttribute;
import com.github.clevernucleus.playerex.api.attribute.IPlayerAttributes;
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 @@ -14,6 +15,8 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.AbstractArrow;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.server.ServerStartingEvent;
import net.minecraftforge.eventbus.api.Event.Result;
import net.minecraftforge.eventbus.api.EventPriority;
Expand Down Expand Up @@ -105,40 +108,49 @@ public static void serverLoad(final ServerStartingEvent par0) {
public static void onCapabilityAttachEntity(final net.minecraftforge.event.AttachCapabilitiesEvent<Entity> par0) {
if(par0.getObject() instanceof Player) {
par0.addCapability(new ResourceLocation(ExAPI.MODID, "playerattributes"), new CapabilityProvider());
System.out.println("attach to " + par0.getObject().getStringUUID() + " " + par0.getObject().level.isClientSide());
}
}

/**
* Event firing when the player gets cloned.
* @param par0
*/

// for some reason the capability doesnt seem to be present on the PlayerEvent.Clone, im sure im just being dumb somehow but maybe its about isAlive==false
private static LazyOptional<IPlayerAttributes> lastDiedPlayerAttributes = null;

@SubscribeEvent
public static void onPlayerEntityCloned(LivingDeathEvent event) {
if (event.getEntityLiving() instanceof Player && !event.getEntityLiving().level.isClientSide()){
lastDiedPlayerAttributes = ExAPI.playerAttributes((Player) event.getEntityLiving());
}
}

@SubscribeEvent
public static void onPlayerEntityCloned(final net.minecraftforge.event.entity.player.PlayerEvent.Clone par0) {
Player var0 = par0.getPlayer();
Player var1 = par0.getOriginal();

if(var0.level.isClientSide) return;
Player newPlayer = par0.getPlayer();
Player oldPlayer = par0.getOriginal();

LazyOptional<IPlayerAttributes> oldAttributes = ExAPI.playerAttributes(oldPlayer).isPresent() ? ExAPI.playerAttributes(oldPlayer) : lastDiedPlayerAttributes;

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

return;
}

try {
ExAPI.playerAttributes(var0).ifPresent(par1 -> {
ExAPI.playerAttributes(var1).ifPresent(par2 -> {
ExAPI.playerAttributes(newPlayer).ifPresent(par1 -> {
oldAttributes.ifPresent(par2 -> {
par1.read(par2.write());
});
});
} catch(Exception parE) {}
update(var0);
sync(var0);

update(newPlayer);
sync(newPlayer);

if(par0.isWasDeath()) {
var0.heal(var0.getMaxHealth());
newPlayer.heal(newPlayer.getMaxHealth());
}
}

Expand Down Expand Up @@ -254,7 +266,7 @@ public static void onExperienceProcessed(final net.minecraftforge.event.entity.p

int var1 = par0.getAmount();
int var2 = Math.round((float)var1 * CommonConfig.COMMON.experienceSplit.get().floatValue() / 100F);
int var3 = Math.round((float)var1 * (100F - CommonConfig.COMMON.experienceSplit.get().floatValue()) / 100F);
int var3 = CommonConfig.COMMON.xpGetsSplit.get() ? Math.round((float)var1 * (100F - CommonConfig.COMMON.experienceSplit.get().floatValue()) / 100F) : par0.getAmount();

ExAPI.playerAttributes(var0).ifPresent(var -> {
var.add(var0, PlayerAttributes.EXPERIENCE, var2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static class Common {
public final IntValue constitution, strength, dexterity, intelligence, luckiness;
/** expCoeff parameters. */
public final DoubleValue offset, scale, experienceSplit;
public final BooleanValue xpGetsSplit;
/** reset attributes on death */
public final BooleanValue resetOnDeath;

Expand Down Expand Up @@ -100,7 +101,8 @@ public Common(ForgeConfigSpec.Builder par0) {
par0.push("experienceSplit");

this.experienceSplit = par0.comment("The percentage of experience that contributes to PlayerEx levels.").translation(ExAPI.MODID + ".config.common.experiencesplit").defineInRange("experienceSplit", 50D, 1D, 99D);

this.xpGetsSplit = par0.comment("When true, vanilla xp gain will be reduced by the percentage that contributes to PlayerEx levels. When false, you gain the normal amount of vanilla xp regardless and experienceSplit just determines how fast you gain PlayerEx levels.").translation(ExAPI.MODID + ".config.common.xpGetsSplit").define("xpGetsSplit", true);

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

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

[[mods]]
modId="playerex"
version="1.3.0"
version="1.3.2"
displayName="Player Ex"
displayURL="https://github.com/LukeGrahamLandryMC/PlayerEx"
logoFile="logo.png"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/playerex/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"playerex.config.common.intelligence": "Intelligence",
"playerex.config.common.luckiness": "Luckiness",
"playerex.config.common.experiencesplit": "The percentage of experience that contributes to PlayerEx levels.",
"playerex.config.common.xpGetsSplit": "When true, vanilla xp gain will be reduced by the percentage that contributes to PlayerEx levels. When false, you gain the normal amount of vanilla xp regardless and experienceSplit just determines how fast you gain PlayerEx levels.",
"playerex.config.common.offset": "Exp Coeff Offset",
"playerex.config.common.scale": "Exp Coeff Scaler",
"key.playerex.hud": "Additional HUD",
Expand Down

0 comments on commit 67f660d

Please sign in to comment.