mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 18:29:05 +00:00
IModelData:
-Implemented hidePart() abd hidden() functions
This commit is contained in:
1 parent
9a77e2f146
commit
6913cadc79
12 files changed
+101
-47
No files matched your search
@@ -163,7 +163,7 @@ public class DataDisplay {
|
||||
|
||||
animationData.readFromNBT(nbttagcompound);
|
||||
|
||||
modelSize = ValueUtil.CorrectInt(nbttagcompound.getInteger("Size"), 1, Integer.MAX_VALUE);
|
||||
modelSize = ValueUtil.clamp(nbttagcompound.getInteger("Size"), 1, Integer.MAX_VALUE);
|
||||
if(modelSize > ConfigMain.NpcSizeLimit)
|
||||
modelSize = ConfigMain.NpcSizeLimit;
|
||||
|
||||
@@ -253,7 +253,7 @@ public class DataDisplay {
|
||||
public void setMarkovGender(int gender) {
|
||||
if(markovGender == gender)
|
||||
return;
|
||||
this.markovGender = ValueUtil.CorrectInt(gender, 0, 2);
|
||||
this.markovGender = ValueUtil.clamp(gender, 0, 2);
|
||||
}
|
||||
|
||||
public int getMarkovGeneratorId(){
|
||||
@@ -263,7 +263,7 @@ public class DataDisplay {
|
||||
public void setMarkovGeneratorId(int id) {
|
||||
if(markovGeneratorId == id)
|
||||
return;
|
||||
this.markovGeneratorId = ValueUtil.CorrectInt(id, 0, CustomNpcs.MARKOV_GENERATOR.length-1);
|
||||
this.markovGeneratorId = ValueUtil.clamp(id, 0, CustomNpcs.MARKOV_GENERATOR.length-1);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -136,10 +136,10 @@ public class DataStats {
|
||||
|
||||
rangedRange = compound.getInteger("MaxFiringRange");
|
||||
fireRate = compound.getInteger("FireRate");
|
||||
minDelay = ValueUtil.CorrectInt(compound.getInteger("minDelay"), 1, 9999);
|
||||
maxDelay = ValueUtil.CorrectInt(compound.getInteger("maxDelay"), 1, 9999);
|
||||
minDelay = ValueUtil.clamp(compound.getInteger("minDelay"), 1, 9999);
|
||||
maxDelay = ValueUtil.clamp(compound.getInteger("maxDelay"), 1, 9999);
|
||||
burstCount = compound.getInteger("BurstCount");
|
||||
shotCount = ValueUtil.CorrectInt(compound.getInteger("ShotCount"), 1, 10);
|
||||
shotCount = ValueUtil.clamp(compound.getInteger("ShotCount"), 1, 10);
|
||||
accuracy = compound.getInteger("Accuracy");
|
||||
|
||||
pDamage = compound.getFloat("pDamage");
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import noppes.npcs.api.entity.data.IModelData;
|
||||
import noppes.npcs.api.entity.data.IModelRotate;
|
||||
import noppes.npcs.api.entity.data.IModelScale;
|
||||
import noppes.npcs.util.ValueUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -174,6 +175,43 @@ public class ModelDataShared implements IModelData {
|
||||
return (1 - modelScale.legs.scaleY) * 0.75f;
|
||||
}
|
||||
|
||||
// Hide Body Parts
|
||||
// [0: Head, 1: Body, 2: Arms, 3: Legs]
|
||||
// [0: None, 1: Both, 2: Right, 3: Left]
|
||||
public void hidePart(int part, byte hide) {
|
||||
part = ValueUtil.clamp(part,0,3);
|
||||
hide = part > 1 ? ValueUtil.clamp(hide,(byte) 0,(byte) 3) : ValueUtil.clamp(hide,(byte) 0,(byte) 1);
|
||||
switch (part) {
|
||||
case 0:
|
||||
this.hideHead = hide;
|
||||
break;
|
||||
case 1:
|
||||
this.hideBody = hide;
|
||||
break;
|
||||
case 2:
|
||||
this.hideArms = hide;
|
||||
break;
|
||||
case 3:
|
||||
this.hideLegs = hide;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public int hidden(int part) {
|
||||
part = ValueUtil.clamp(part,0,3);
|
||||
switch (part) {
|
||||
case 0:
|
||||
return this.hideHead;
|
||||
case 1:
|
||||
return this.hideBody;
|
||||
case 2:
|
||||
return this.hideArms;
|
||||
case 3:
|
||||
return this.hideLegs;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void enableRotation(boolean enableRotation) {
|
||||
this.enableRotation = enableRotation;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class ModelRotate implements IModelRotate {
|
||||
}
|
||||
|
||||
public IModelRotatePart getPart(int part) {
|
||||
switch (ValueUtil.CorrectInt(part,0,5)) {
|
||||
switch (ValueUtil.clamp(part,0,5)) {
|
||||
case 0:
|
||||
return head;
|
||||
case 1:
|
||||
|
||||
@@ -19,15 +19,15 @@ public class ModelRotatePart implements IModelRotatePart {
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound){
|
||||
disabled = compound.getBoolean("Disabled");
|
||||
rotationX = ValueUtil.correctFloat(compound.getFloat("RotationX"), -0.5f, 0.5f);
|
||||
rotationY = ValueUtil.correctFloat(compound.getFloat("RotationY"), -0.5f, 0.5f);
|
||||
rotationZ = ValueUtil.correctFloat(compound.getFloat("RotationZ"), -0.5f, 0.5f);
|
||||
rotationX = ValueUtil.clamp(compound.getFloat("RotationX"), -0.5f, 0.5f);
|
||||
rotationY = ValueUtil.clamp(compound.getFloat("RotationY"), -0.5f, 0.5f);
|
||||
rotationZ = ValueUtil.clamp(compound.getFloat("RotationZ"), -0.5f, 0.5f);
|
||||
}
|
||||
|
||||
public void setRotation(float x, float y, float z) {
|
||||
this.rotationX = ValueUtil.correctFloat(x, -0.5f, 0.5f);
|
||||
this.rotationY = ValueUtil.correctFloat(y, -0.5f, 0.5f);
|
||||
this.rotationZ = ValueUtil.correctFloat(z, -0.5f, 0.5f);
|
||||
this.rotationX = ValueUtil.clamp(x, -0.5f, 0.5f);
|
||||
this.rotationY = ValueUtil.clamp(y, -0.5f, 0.5f);
|
||||
this.rotationZ = ValueUtil.clamp(z, -0.5f, 0.5f);
|
||||
}
|
||||
|
||||
public float getRotateX() {
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ModelScale implements IModelScale {
|
||||
|
||||
@Override
|
||||
public IModelScalePart getPart(int part) {
|
||||
switch (ValueUtil.CorrectInt(part,0,3)) {
|
||||
switch (ValueUtil.clamp(part,0,3)) {
|
||||
case 0:
|
||||
return head;
|
||||
case 1:
|
||||
|
||||
@@ -17,9 +17,9 @@ public class ModelScalePart implements IModelScalePart {
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound compound){
|
||||
scaleX = ValueUtil.correctFloat(compound.getFloat("ScaleX"), 0.5f, 1.5f);
|
||||
scaleY = ValueUtil.correctFloat(compound.getFloat("ScaleY"), 0.5f, 1.5f);
|
||||
scaleZ = ValueUtil.correctFloat(compound.getFloat("ScaleZ"), 0.5f, 1.5f);
|
||||
scaleX = ValueUtil.clamp(compound.getFloat("ScaleX"), 0.5f, 1.5f);
|
||||
scaleY = ValueUtil.clamp(compound.getFloat("ScaleY"), 0.5f, 1.5f);
|
||||
scaleZ = ValueUtil.clamp(compound.getFloat("ScaleZ"), 0.5f, 1.5f);
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
@@ -32,9 +32,9 @@ public class ModelScalePart implements IModelScalePart {
|
||||
}
|
||||
|
||||
public void setScale(float x, float y, float z) {
|
||||
scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f);
|
||||
scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f);
|
||||
scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f);
|
||||
scaleX = ValueUtil.clamp(x, 0.5f, 1.5f);
|
||||
scaleY = ValueUtil.clamp(y, 0.5f, 1.5f);
|
||||
scaleZ = ValueUtil.clamp(z, 0.5f, 1.5f);
|
||||
}
|
||||
|
||||
public float getScaleX() {
|
||||
|
||||
@@ -187,7 +187,7 @@ public class QuestItem extends QuestInterface implements IQuestItem {
|
||||
}
|
||||
}
|
||||
|
||||
return ValueUtil.CorrectInt(count, 0, this.questItem.stackSize);
|
||||
return ValueUtil.clamp(count, 0, this.questItem.stackSize);
|
||||
}
|
||||
|
||||
public void setProgress(int progress) {
|
||||
|
||||
@@ -939,9 +939,9 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
|
||||
public void setHeadScale(float x, float y, float z){
|
||||
if(npc instanceof EntityCustomNpc) {
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.head.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.head.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.head.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.head.scaleX = ValueUtil.clamp(x, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.head.scaleY = ValueUtil.clamp(y, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.head.scaleZ = ValueUtil.clamp(z, 0.5f, 1.5f);
|
||||
|
||||
npc.script.clientNeedsUpdate = true;
|
||||
}
|
||||
@@ -949,9 +949,9 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
|
||||
public void setBodyScale(float x, float y, float z){
|
||||
if(npc instanceof EntityCustomNpc) {
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.body.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.body.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.body.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.body.scaleX = ValueUtil.clamp(x, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.body.scaleY = ValueUtil.clamp(y, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.body.scaleZ = ValueUtil.clamp(z, 0.5f, 1.5f);
|
||||
|
||||
npc.script.clientNeedsUpdate = true;
|
||||
}
|
||||
@@ -959,9 +959,9 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
|
||||
public void setArmsScale(float x, float y, float z){
|
||||
if(npc instanceof EntityCustomNpc) {
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.arms.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.arms.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.arms.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.arms.scaleX = ValueUtil.clamp(x, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.arms.scaleY = ValueUtil.clamp(y, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.arms.scaleZ = ValueUtil.clamp(z, 0.5f, 1.5f);
|
||||
|
||||
npc.script.clientNeedsUpdate = true;
|
||||
}
|
||||
@@ -969,9 +969,9 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
|
||||
public void setLegsScale(float x, float y, float z){
|
||||
if(npc instanceof EntityCustomNpc) {
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.legs.scaleX = ValueUtil.correctFloat(x, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.legs.scaleY = ValueUtil.correctFloat(y, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.legs.scaleZ = ValueUtil.correctFloat(z, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.legs.scaleX = ValueUtil.clamp(x, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.legs.scaleY = ValueUtil.clamp(y, 0.5f, 1.5f);
|
||||
((EntityCustomNpc) this.npc).modelData.modelScale.legs.scaleZ = ValueUtil.clamp(z, 0.5f, 1.5f);
|
||||
|
||||
npc.script.clientNeedsUpdate = true;
|
||||
}
|
||||
@@ -982,7 +982,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
* @param resistance Explosion resistance (0-2) default is 1
|
||||
*/
|
||||
public void setExplosionResistance(float resistance){
|
||||
npc.stats.resistances.explosion = ValueUtil.correctFloat(resistance, 0, 2);
|
||||
npc.stats.resistances.explosion = ValueUtil.clamp(resistance, 0, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -997,7 +997,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
* @param resistance Melee resistance (0-2) default is 1
|
||||
*/
|
||||
public void setMeleeResistance(float resistance){
|
||||
npc.stats.resistances.playermelee = ValueUtil.correctFloat(resistance, 0, 2);
|
||||
npc.stats.resistances.playermelee = ValueUtil.clamp(resistance, 0, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1011,7 +1011,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
* @param resistance Arrow resistance (0-2) default is 1
|
||||
*/
|
||||
public void setArrowResistance(float resistance){
|
||||
npc.stats.resistances.arrow = ValueUtil.correctFloat(resistance, 0, 2);
|
||||
npc.stats.resistances.arrow = ValueUtil.clamp(resistance, 0, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1025,7 +1025,7 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
|
||||
* @param resistance Knockback resistance (0-2) default is 1
|
||||
*/
|
||||
public void setKnockbackResistance(double resistance){
|
||||
npc.stats.resistances.knockback = ValueUtil.correctFloat((float) resistance, 0, 2);
|
||||
npc.stats.resistances.knockback = ValueUtil.clamp((float) resistance, 0, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -184,7 +184,7 @@ public class ScriptPixelmon<T extends EntityTameable> extends ScriptAnimal<T> im
|
||||
* @param value 0-255
|
||||
*/
|
||||
public void setHapiness(int value){
|
||||
value = ValueUtil.CorrectInt(value, 0, 255);
|
||||
value = ValueUtil.clamp(value, 0, 255);
|
||||
compound.setInteger("Friendship", value);
|
||||
pixelmon.readEntityFromNBT(compound);
|
||||
}
|
||||
@@ -241,7 +241,7 @@ public class ScriptPixelmon<T extends EntityTameable> extends ScriptAnimal<T> im
|
||||
}
|
||||
|
||||
public void setMove(int slot, String move){
|
||||
slot = ValueUtil.CorrectInt(slot, 0, 3);
|
||||
slot = ValueUtil.clamp(slot, 0, 3);
|
||||
int id = PixelmonHelper.getAttackID(move);
|
||||
compound.removeTag("PixelmonMovePP" + slot);
|
||||
compound.removeTag("PixelmonMovePPBase" + slot);
|
||||
|
||||
@@ -535,9 +535,9 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
|
||||
* @param z The z position
|
||||
*/
|
||||
public void setSpawnpoint(int x, int y, int z){
|
||||
x = ValueUtil.CorrectInt(x, -30000000, 30000000);
|
||||
z = ValueUtil.CorrectInt(z, -30000000, 30000000);
|
||||
y = ValueUtil.CorrectInt(y, 0, 256);
|
||||
x = ValueUtil.clamp(x, -30000000, 30000000);
|
||||
z = ValueUtil.clamp(z, -30000000, 30000000);
|
||||
y = ValueUtil.clamp(y, 0, 256);
|
||||
player.setSpawnChunk(new ChunkCoordinates(x, y, z), true);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,19 @@
|
||||
package noppes.npcs.util;
|
||||
|
||||
public class ValueUtil {
|
||||
public static float correctFloat(float given, float min, float max){
|
||||
public static float clamp(float given, float min, float max){
|
||||
if(given < min)
|
||||
return min;
|
||||
return Math.min(given, max);
|
||||
}
|
||||
|
||||
public static int clamp(int given, int min, int max) {
|
||||
if(given < min)
|
||||
return min;
|
||||
return Math.min(given, max);
|
||||
}
|
||||
|
||||
public static byte clamp(byte given, byte min, byte max) {
|
||||
if(given < min)
|
||||
return min;
|
||||
if(given > max)
|
||||
@@ -9,11 +21,15 @@ public class ValueUtil {
|
||||
return given;
|
||||
}
|
||||
|
||||
public static int CorrectInt(int given, int min, int max) {
|
||||
public static double clamp(double given, double min, double max) {
|
||||
if(given < min)
|
||||
return min;
|
||||
if(given > max)
|
||||
return max;
|
||||
return given;
|
||||
return Math.min(given, max);
|
||||
}
|
||||
|
||||
public static long clamp(long given, long min, long max) {
|
||||
if(given < min)
|
||||
return min;
|
||||
return Math.min(given, max);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user