Skip to content

Commit

Permalink
Version 1.1.3
Browse files Browse the repository at this point in the history
+Added useful limit data for modders to use; each attribute is assigned a minimum, maximum, increment value and chance weighting. None of these do anything or influence any function of the api mod, they are simply there so that other mods that have to assign values no longer have to and are compatible with other attributes.

+Updated to 1.1.3.
  • Loading branch information
CleverNucleus committed Jan 8, 2021
1 parent f902041 commit 3bff108
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 48 deletions.
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.2
mod_version=1.1.3
mod_group=com.github.clevernucleus
mod_name=playerex
mod_author=CleverNucleus
65 changes: 65 additions & 0 deletions src/main/java/com/github/clevernucleus/playerex/api/Limit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.github.clevernucleus.playerex.api;

/**
* Holds four values needed for attribute manipulation required by chance-based mods.
*/
public class Limit {
private double increment, minValue, maxValue, weight;

private Limit(final double par0, final double par1, final double par2, final double par3) {
this.increment = (par0 < par2 ? par0 : 0D);
this.minValue = (par1 < par2 ? par1 : 0D);
this.maxValue = (par2 > par1 ? par2 : par0 + par1);
this.weight = Math.min(Math.max(par3, 0D), 1D);
}

/**
* @param par0 Increment Value (must be less than the Max Value).
* @param par1 Min Value (must be less than the Max Value).
* @param par2 Max Value (must be greater than the Min Value).
* @param par3 Weight - for random chance; could be interpreted as how rare this attribute is (must be between 0 and 1).
* @return A new Limit instance holding the input parameters.
*/
public static Limit hold(final double par0, final double par1, final double par2, final double par3) {
return new Limit(par0, par1, par2, par3);
}

/**
* @return A null-equivalent Limit instance holding [0D, 0D, 0D, 0D].
*/
public static Limit none() {
return new Limit(0D, 0D, 0D, 0D);
}

public double increment() {
return this.increment;
}

public double minValue() {
return this.minValue;
}

public double maxValue() {
return this.maxValue;
}

public double weight() {
return this.weight;
}

@Override
public boolean equals(Object par0) {
if(par0 == null) return false;
if(par0 == this) return true;
if(!(par0 instanceof Limit)) return false;

Limit var0 = (Limit)par0;

return toString().equals(var0.toString());
}

@Override
public String toString() {
return "[incr=" + this.increment + ",min=" + this.minValue + ",max=" + this.maxValue + ",weight=" + this.weight + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.UUID;

import com.github.clevernucleus.playerex.api.Limit;

import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.util.ResourceLocation;

Expand All @@ -27,6 +29,11 @@ enum Type {
*/
UUID uuid();

/**
* @return The attributes Limit instance, available for external use by modders.
*/
Limit limit();

/**
* @return Should be in the format of (YourMod.MODID, "name_of_attribute"). Example: {@link PlayerAttributes#CONSTITUTION} is (ExAPI.MODID, "constitution").
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
import java.util.UUID;
import java.util.function.Supplier;

import com.github.clevernucleus.playerex.api.Limit;

import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.util.ResourceLocation;

public class PlayerAttribute implements IPlayerAttribute {
private IPlayerAttribute.Type type;
private Supplier<Attribute> attribute;
private ResourceLocation registryName;
private Limit limit;
private UUID uuid;

public PlayerAttribute(final ResourceLocation par0, final UUID par1, final IPlayerAttribute.Type par2, final Supplier<Attribute> par3) {
public PlayerAttribute(final ResourceLocation par0, final UUID par1, final Limit par2, final IPlayerAttribute.Type par3, final Supplier<Attribute> par4) {
this.registryName = par0;
this.uuid = par1;
this.type = par2;
this.attribute = par3;
this.limit = par2;
this.type = par3;
this.attribute = par4;
}

@Override
Expand All @@ -29,6 +33,11 @@ public UUID uuid() {
return this.uuid;
}

@Override
public Limit limit() {
return this.limit;
}

@Override
public ResourceLocation registryName() {
return this.registryName;
Expand Down
Loading

0 comments on commit 3bff108

Please sign in to comment.