Skip to content

Instantly share code, notes, and snippets.

@ZornTaov
Created April 6, 2013 02:37
Show Gist options
  • Save ZornTaov/5324474 to your computer and use it in GitHub Desktop.
Save ZornTaov/5324474 to your computer and use it in GitHub Desktop.
package zornco.reploidcraft.modules;
import net.machinemuse.api.MuseItemUtils;
import net.machinemuse.powersuits.powermodule.PropertyModifierLinearAdditive;
import net.minecraft.nbt.NBTTagCompound;
public class PropertyModifierIntLinearAdditive extends PropertyModifierLinearAdditive {
protected int roundTo = 0;
protected int offset = 0;
public PropertyModifierIntLinearAdditive(String tradeoffName, double multiplier, int roundTo, int offset) {
super(tradeoffName, multiplier);
this.roundTo = roundTo;
this.offset = offset;
}
@Override
public double applyModifier(NBTTagCompound moduleTag, double value) {
long result = (long)(value + multiplier * MuseItemUtils.getDoubleOrZero(moduleTag, tradeoffName));
return roundWithOffset(result, roundTo, offset);
}
public long roundWithOffset(double input, int roundTo, int offset){
return Math.round((input + offset)/roundTo)*roundTo - offset;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment