mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 06:09:05 +00:00
Enabled fly button in movement, and extended max values for several NPC attributes, converting some to floats and doubles.
NPCs fly with speed based on their movement speed now.
This commit is contained in:
1 parent
44d4e74279
commit
23686dc3b8
35 files changed
+258
-189
No files matched your search
@@ -8,10 +8,14 @@ import net.minecraft.client.gui.GuiTextField;
|
||||
public class GuiNpcTextField extends GuiTextField{
|
||||
public boolean enabled = true;
|
||||
public boolean inMenu = true;
|
||||
public boolean numbersOnly = false;
|
||||
public boolean integersOnly = false;
|
||||
public boolean doublesOnly = false;
|
||||
public boolean floatsOnly = false;
|
||||
private ITextfieldListener listener;
|
||||
public int id;
|
||||
public int min = 0,max = Integer.MAX_VALUE,def = 0;
|
||||
public double minDouble = 0, maxDouble = Double.MAX_VALUE, defDouble = 0;
|
||||
public float minFloat = 0, maxFloat = Float.MAX_VALUE, defFloat = 0;
|
||||
private static GuiNpcTextField activeTextfield = null;
|
||||
public boolean canEdit = true;
|
||||
|
||||
@@ -37,7 +41,7 @@ public class GuiNpcTextField extends GuiTextField{
|
||||
}
|
||||
|
||||
private boolean charAllowed(char c, int i){
|
||||
if(!numbersOnly || Character.isDigit(c))
|
||||
if(!integersOnly || Character.isDigit(c))
|
||||
return true;
|
||||
for(int j : allowedSpecialChars)
|
||||
if(j == i)
|
||||
@@ -61,6 +65,7 @@ public class GuiNpcTextField extends GuiTextField{
|
||||
public int getInteger(){
|
||||
return Integer.parseInt(getText());
|
||||
}
|
||||
|
||||
public boolean isInteger(){
|
||||
try{
|
||||
Integer.parseInt(getText());
|
||||
@@ -69,6 +74,33 @@ public class GuiNpcTextField extends GuiTextField{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public double getDouble(){
|
||||
return Double.parseDouble(getText());
|
||||
}
|
||||
|
||||
public boolean isDouble() {
|
||||
try{
|
||||
Double.parseDouble(getText());
|
||||
return true;
|
||||
}catch(NumberFormatException e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public float getFloat(){
|
||||
return Float.parseFloat(getText());
|
||||
}
|
||||
|
||||
public boolean isFloat() {
|
||||
try{
|
||||
Float.parseFloat(getText());
|
||||
return true;
|
||||
}catch(NumberFormatException e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int i, int j, int k){
|
||||
if(!canEdit)
|
||||
@@ -85,30 +117,58 @@ public class GuiNpcTextField extends GuiTextField{
|
||||
}
|
||||
|
||||
public void unFocused(){
|
||||
if(numbersOnly){
|
||||
if(integersOnly && !doublesOnly && !floatsOnly){
|
||||
if(isEmpty() || !isInteger())
|
||||
setText(def + "");
|
||||
else if( getInteger() < min)
|
||||
setText(def+"");
|
||||
else if(getInteger() < min)
|
||||
setText(min+"");
|
||||
else if(getInteger() > max)
|
||||
setText(max+"");
|
||||
}
|
||||
else if(doublesOnly && !floatsOnly){
|
||||
if(isEmpty() || !isDouble())
|
||||
setText(defDouble +"");
|
||||
else if(getDouble() < minDouble)
|
||||
setText(minDouble +"");
|
||||
else if(getDouble() > maxDouble)
|
||||
setText(maxDouble +"");
|
||||
}
|
||||
else if(floatsOnly){
|
||||
if(isEmpty() || !isFloat())
|
||||
setText(defFloat +"");
|
||||
else if(getFloat() < minFloat)
|
||||
setText(minFloat +"");
|
||||
else if(getFloat() > maxFloat)
|
||||
setText(maxFloat +"");
|
||||
}
|
||||
|
||||
if(listener != null)
|
||||
listener.unFocused(this);
|
||||
|
||||
if(this == activeTextfield)
|
||||
activeTextfield = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawTextBox()
|
||||
{
|
||||
if(enabled)
|
||||
super.drawTextBox();
|
||||
}
|
||||
public void setMinMaxDefault(int i, int j, int k) {
|
||||
min = i;
|
||||
max = j;
|
||||
def = k;
|
||||
public void setMinMaxDefault(int min, int max, int def) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.def = def;
|
||||
}
|
||||
public void setMinMaxDefaultDouble(double min, double max, double def) {
|
||||
minDouble = min;
|
||||
maxDouble = max;
|
||||
defDouble = def;
|
||||
}
|
||||
public void setMinMaxDefaultFloat(float min, float max, float def) {
|
||||
minFloat = min;
|
||||
maxFloat = max;
|
||||
defFloat = def;
|
||||
}
|
||||
public static void unfocus() {
|
||||
GuiNpcTextField prev = activeTextfield;
|
||||
@@ -122,8 +182,17 @@ public class GuiNpcTextField extends GuiTextField{
|
||||
drawTextBox();
|
||||
}
|
||||
|
||||
public GuiNpcTextField setNumbersOnly() {
|
||||
numbersOnly = true;
|
||||
public GuiNpcTextField setIntegersOnly() {
|
||||
integersOnly = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GuiNpcTextField setDoublesOnly() {
|
||||
doublesOnly = true;
|
||||
return this;
|
||||
}
|
||||
public GuiNpcTextField setFloatsOnly() {
|
||||
floatsOnly = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user