Skip to content
Permalink
Browse files
Add entity immunity functions
  • Loading branch information
PseudoKnight committed May 8, 2020
1 parent ef8ea78 commit 1ffa65d0fb12867e37a1dd3643b13a6e51ede613
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 16 deletions.
@@ -61,8 +61,6 @@ public interface MCLivingEntity extends MCEntity, MCProjectileSource {

int getMaximumAir();

int getMaximumNoDamageTicks();

int getNoDamageTicks();

int getRemainingAir();
@@ -89,8 +87,6 @@ public interface MCLivingEntity extends MCEntity, MCProjectileSource {

void setMaximumAir(int ticks);

void setMaximumNoDamageTicks(int ticks);

void setNoDamageTicks(int ticks);

void setRemainingAir(int ticks);
@@ -189,14 +189,14 @@ public int getMaximumAir() {
return le.getMaximumAir();
}

@Override
public int getMaximumNoDamageTicks() {
return le.getMaximumNoDamageTicks();
}

@Override
public int getNoDamageTicks() {
return le.getNoDamageTicks();
// Minecraft checks for noDamageTicks > 10 before causing damage.
// Since this is useless and confusing, return the actual amount of immunity ticks.
if(le.getNoDamageTicks() < 10) {
return 0;
}
return le.getNoDamageTicks() - 10;
}

@Override
@@ -263,14 +263,10 @@ public void setMaximumAir(int ticks) {
le.setMaximumAir(ticks);
}

@Override
public void setMaximumNoDamageTicks(int ticks) {
le.setMaximumNoDamageTicks(ticks);
}

@Override
public void setNoDamageTicks(int ticks) {
le.setNoDamageTicks(ticks);
// Minecraft checks for noDamageTicks > 10 before causing damage, so adjust for the actual immunity ticks.
le.setNoDamageTicks(ticks + 10);
}

@Override
@@ -2175,4 +2175,54 @@ public Version since() {
return MSVersion.V3_3_4;
}
}

@api(environments = {CommandHelperEnvironment.class})
public static class get_entity_immunity_ticks extends EntityManagement.EntityGetterFunction {

@Override
public String getName() {
return "get_entity_immunity_ticks";
}

@Override
public String docs() {
return "int {entityUUID} Gets the number of immunity ticks a living entity has remaining."
+ " After being damaged, an entity is given 10 ticks of immunity from equal or lesser damage.";
}

@Override
public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
return new CInt(Static.getLivingEntity(args[0], t).getNoDamageTicks(), t);
}

@Override
public MSVersion since() {
return MSVersion.V3_3_4;
}
}

@api(environments = {CommandHelperEnvironment.class})
public static class set_entity_immunity_ticks extends EntityManagement.EntitySetterFunction {

@Override
public String getName() {
return "set_entity_immunity_ticks";
}

@Override
public String docs() {
return "void {entityUUID, int} Sets the number of immunity ticks a living entity has remaining.";
}

@Override
public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
Static.getLivingEntity(args[0], t).setNoDamageTicks(Static.getInt32(args[1], t));
return CVoid.VOID;
}

@Override
public MSVersion since() {
return MSVersion.V3_3_4;
}
}
}

0 comments on commit 1ffa65d

Please sign in to comment.