mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 03:47:27 +00:00
Merge branch 'dev' into patch
# Conflicts: # src/api
This commit is contained in:
commit
dc42beee15
2 files changed
+153
-14
No files matched your search
@@ -1,8 +1,5 @@
|
||||
package noppes.npcs.scripted.entity;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.IProjectile;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -12,9 +9,6 @@ import noppes.npcs.api.item.IItemStack;
|
||||
import noppes.npcs.scripted.CustomNPCsException;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ScriptDBCPlayer<T extends EntityPlayerMP> extends ScriptPlayer<T> implements IDBCPlayer {
|
||||
public T player;
|
||||
|
||||
@@ -522,8 +516,9 @@ public class ScriptDBCPlayer<T extends EntityPlayerMP> extends ScriptPlayer<T> i
|
||||
return player.getEntityData().getCompoundTag("PlayerPersisted").getByte("jrmcState2");
|
||||
}
|
||||
|
||||
public double getFormMastery(String formTree, byte form) {
|
||||
public double getRacialFormMastery(byte form) {
|
||||
try {
|
||||
String formTree = this.getRacialTreeName();
|
||||
if (player.getEntityData().getCompoundTag("PlayerPersisted").hasKey("jrmcFormMastery" + formTree)) {
|
||||
String[] formMasteries = player.getEntityData().getCompoundTag("PlayerPersisted").
|
||||
getString("jrmcFormMastery" + formTree).split(";");
|
||||
@@ -534,8 +529,9 @@ public class ScriptDBCPlayer<T extends EntityPlayerMP> extends ScriptPlayer<T> i
|
||||
return 0.0D;
|
||||
}
|
||||
|
||||
public void setFormMastery(String formTree, byte form, double value) {
|
||||
public void setRacialFormMastery(byte form, double value) {
|
||||
try {
|
||||
String formTree = this.getRacialTreeName();
|
||||
if (player.getEntityData().getCompoundTag("PlayerPersisted").hasKey("jrmcFormMastery" + formTree)) {
|
||||
String[] formMasteries = player.getEntityData().getCompoundTag("PlayerPersisted").
|
||||
getString("jrmcFormMastery" + formTree).split(";");
|
||||
@@ -558,8 +554,9 @@ public class ScriptDBCPlayer<T extends EntityPlayerMP> extends ScriptPlayer<T> i
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
public void addFormMastery(String formTree, byte form, double value) {
|
||||
public void addRacialFormMastery(byte form, double value) {
|
||||
try {
|
||||
String formTree = this.getRacialTreeName();
|
||||
if (player.getEntityData().getCompoundTag("PlayerPersisted").hasKey("jrmcFormMastery" + formTree)) {
|
||||
String[] formMasteries = player.getEntityData().getCompoundTag("PlayerPersisted").
|
||||
getString("jrmcFormMastery" + formTree).split(";");
|
||||
@@ -583,6 +580,107 @@ public class ScriptDBCPlayer<T extends EntityPlayerMP> extends ScriptPlayer<T> i
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
private String getRacialTreeName() {
|
||||
switch (this.getRace()) {
|
||||
case 0:
|
||||
return "Racial_Human";
|
||||
case 1:
|
||||
return "Racial_Saiyan";
|
||||
case 2:
|
||||
return "Racial_Half-Saiyan";
|
||||
case 3:
|
||||
return "Racial_Namekian";
|
||||
case 4:
|
||||
return "Racial_Arcosian";
|
||||
case 5:
|
||||
return "Racial_Majin";
|
||||
}
|
||||
return "Racial_Human";
|
||||
}
|
||||
|
||||
public double getOtherFormMastery(String formName) {
|
||||
try {
|
||||
if (player.getEntityData().getCompoundTag("PlayerPersisted").hasKey("jrmcFormMasteryNonRacial")) {
|
||||
String masteryData = player.getEntityData().getCompoundTag("PlayerPersisted").
|
||||
getString("jrmcFormMasteryNonRacial");
|
||||
if (!masteryData.contains(formName)) {
|
||||
return 0.0D;
|
||||
}
|
||||
|
||||
String[] formMasteries = masteryData.split(";");
|
||||
for (String masteryString : formMasteries) {
|
||||
if (masteryString.split(",")[0].equals(formName)) {
|
||||
return Double.parseDouble(masteryString.split(",")[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
return 0.0D;
|
||||
}
|
||||
|
||||
public void setOtherFormMastery(String formName, double value) {
|
||||
try {
|
||||
if (player.getEntityData().getCompoundTag("PlayerPersisted").hasKey("jrmcFormMasteryNonRacial")) {
|
||||
String masteryData = player.getEntityData().getCompoundTag("PlayerPersisted").
|
||||
getString("jrmcFormMasteryNonRacial");
|
||||
if (!masteryData.contains(formName)) {
|
||||
return;
|
||||
}
|
||||
String[] formMasteries = masteryData.split(";");
|
||||
|
||||
for (int i = 0; i < formMasteries.length; i++) {
|
||||
String name = formMasteries[i].split(",")[0];
|
||||
if (name.equals(formName)) {
|
||||
formMasteries[i] = name + "," + value;
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder masteryString = new StringBuilder();
|
||||
for (int i = 0; i < formMasteries.length; i++) {
|
||||
masteryString.append(formMasteries[i]);
|
||||
if (i < formMasteries.length - 1) {
|
||||
masteryString.append(';');
|
||||
}
|
||||
}
|
||||
|
||||
player.getEntityData().getCompoundTag("PlayerPersisted").
|
||||
setString("jrmcFormMasteryNonRacial", String.valueOf(masteryString));
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
public void addOtherFormMastery(String formName, double value) {
|
||||
try {
|
||||
if (player.getEntityData().getCompoundTag("PlayerPersisted").hasKey("jrmcFormMasteryNonRacial")) {
|
||||
String masteryData = player.getEntityData().getCompoundTag("PlayerPersisted").
|
||||
getString("jrmcFormMasteryNonRacial");
|
||||
if (!masteryData.contains(formName)) {
|
||||
return;
|
||||
}
|
||||
String[] formMasteries = masteryData.split(";");
|
||||
|
||||
for (int i = 0; i < formMasteries.length; i++) {
|
||||
String name = formMasteries[i].split(",")[0];
|
||||
if (name.equals(formName)) {
|
||||
double newMastery = Double.parseDouble(formMasteries[i].split(",")[1]) + value;
|
||||
formMasteries[i] = name + "," + newMastery;
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder masteryString = new StringBuilder();
|
||||
for (int i = 0; i < formMasteries.length; i++) {
|
||||
masteryString.append(formMasteries[i]);
|
||||
if (i < formMasteries.length - 1) {
|
||||
masteryString.append(';');
|
||||
}
|
||||
}
|
||||
|
||||
player.getEntityData().getCompoundTag("PlayerPersisted").
|
||||
setString("jrmcFormMasteryNonRacial", String.valueOf(masteryString));
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
public void setPowerPoints(int points){
|
||||
player.getEntityData().getCompoundTag("PlayerPersisted").setInteger("jrmcArcRsrv",points);
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ public class NBTJsonUtil {
|
||||
json = json.trim();
|
||||
JsonFile file = new JsonFile(json);
|
||||
if(!json.startsWith("{") || !json.endsWith("}"))
|
||||
throw new JsonException("Not properly incapsulated between { }", file);
|
||||
|
||||
throw new JsonException("Not properly encapsulated between { }", file);
|
||||
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
FillCompound(compound, file);
|
||||
return compound;
|
||||
@@ -36,7 +36,7 @@ public class NBTJsonUtil {
|
||||
json.cut(1);
|
||||
if(json.startsWith("}"))
|
||||
return;
|
||||
int index = json.indexOf(":");
|
||||
int index = json.findObjectColonIndex();
|
||||
if(index < 1)
|
||||
throw new JsonException("Expected key after ," ,json);
|
||||
|
||||
@@ -85,6 +85,16 @@ public class NBTJsonUtil {
|
||||
if(!json.startsWith("]")){
|
||||
throw new JsonException("Expected ]", json);
|
||||
}
|
||||
|
||||
if (json.startsWith("]b")) {
|
||||
json.cut(2);
|
||||
byte[] arr = new byte[list.tagCount()];
|
||||
for(int i = 0; list.tagCount() > 0 ; i++){
|
||||
arr[i] = ((NBTTagInt)list.removeTag(0)).func_150290_f();
|
||||
}
|
||||
return new NBTTagByteArray(arr);
|
||||
}
|
||||
|
||||
json.cut(1);
|
||||
|
||||
if(list.func_150303_d() == 3){
|
||||
@@ -156,7 +166,19 @@ public class NBTJsonUtil {
|
||||
private static JsonLine ReadTag(String name, NBTBase base, List<JsonLine> list){
|
||||
if(!name.isEmpty())
|
||||
name = "\"" + name + "\": ";
|
||||
if(base.getId() == 8){//NBTTagString
|
||||
if (base.getId() == 7) {//NBTTagByteArray
|
||||
list.add(new JsonLine(name + "["));
|
||||
byte[] bytes = ((NBTTagByteArray) base).func_150292_c();
|
||||
|
||||
for(int i = 0; i < (bytes.length-1); i++) {
|
||||
list.add(new JsonLine(String.format("%s,", bytes[i])));
|
||||
}
|
||||
if (bytes.length > 0) {
|
||||
list.add(new JsonLine(String.format("%s", bytes[bytes.length-1])));
|
||||
}
|
||||
list.add(new JsonLine("]b"));
|
||||
}
|
||||
else if(base.getId() == 8){//NBTTagString
|
||||
String data = ((NBTTagString)base).func_150285_a_();
|
||||
data = data.replace("\"", "\\\""); //replace " with \"
|
||||
list.add(new JsonLine(name + "\"" + data + "\""));
|
||||
@@ -225,7 +247,8 @@ public class NBTJsonUtil {
|
||||
public boolean reduceTab(){
|
||||
int length = line.length();
|
||||
return length == 1 && (line.endsWith("}") || line.endsWith("]"))
|
||||
|| length == 2 && (line.endsWith("},") ||line.endsWith("],"));
|
||||
|| length == 2 && (line.endsWith("},") ||line.endsWith("],") || line.endsWith("]b"))
|
||||
|| length == 3 && (line.endsWith("]b,"));
|
||||
}
|
||||
|
||||
public boolean increaseTab(){
|
||||
@@ -283,6 +306,24 @@ public class NBTJsonUtil {
|
||||
return "Line: " + lines.length + ", Pos: " + pos + ", Text: " + line;
|
||||
}
|
||||
|
||||
public int findObjectColonIndex() {
|
||||
int trueQuotesAmount = 0;
|
||||
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
if (text.charAt(i) == '"') {
|
||||
if (i > 1 && text.charAt(i-1) != '\\' || i == 0) {
|
||||
trueQuotesAmount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (trueQuotesAmount == 2) {
|
||||
return text.indexOf(":", i);
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public boolean startsWith(String... ss) {
|
||||
for(String s : ss)
|
||||
if(text.startsWith(s))
|
||||
|
||||
Reference in new issue
Block a user