Skip to content

Commit

Permalink
add some null checks to entity breed event
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 29, 2020
1 parent 77015b4 commit 44922eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Expand Up @@ -67,11 +67,9 @@ public boolean couldMatch(ScriptPath path) {

@Override
public boolean matches(ScriptPath path) {

if (!tryEntity(entity, path.eventArgLowerAt(0))) {
return false;
}

if (!runInCheck(path, entity.getLocation())) {
return false;
}
Expand All @@ -98,7 +96,7 @@ public ObjectTag getContext(String name) {
if (name.equals("child")) {
return entity.getDenizenObject();
}
else if (name.equals("breeder")) {
else if (name.equals("breeder") && breeder != null) {
return breeder.getDenizenObject();
}
else if (name.equals("father")) {
Expand All @@ -107,7 +105,7 @@ else if (name.equals("father")) {
else if (name.equals("mother")) {
return mother.getDenizenObject();
}
else if (name.equals("item")) {
else if (name.equals("item") && item != null) {
return item;
}
else if (name.equals("experience")) {
Expand All @@ -130,10 +128,10 @@ public void cancellationChanged() {
public void onEntityBreeds(EntityBreedEvent event) {
Entity entity = event.getEntity();
this.entity = new EntityTag(entity);
breeder = new EntityTag(event.getBreeder());
breeder = event.getBreeder() == null ? null : new EntityTag(event.getBreeder());
father = new EntityTag(event.getFather());
mother = new EntityTag(event.getMother());
item = new ItemTag(event.getBredWith());
item = event.getBredWith() == null ? null : new ItemTag(event.getBredWith());
experience = event.getExperience();
this.event = event;
EntityTag.rememberEntity(entity);
Expand Down
Expand Up @@ -119,6 +119,10 @@ public void adjust(Mechanism mechanism) {
itemStack = CustomNBT.clearNBT(itemStack, CustomNBT.KEY_ATTRIBUTES);
for (String string : list) {
String[] split = string.split("/");
if (split.length != 4) {
Debug.echoError("Invalid nbt_attributes input: must have 4 values per attribute.");
continue;
}
String attribute = EscapeTagBase.unEscape(split[0]);
String slot = EscapeTagBase.unEscape(split[1]);
int op = new ElementTag(split[2]).asInt();
Expand Down

0 comments on commit 44922eb

Please sign in to comment.