Skip to content
Permalink
Browse files

Add villager experience/level and panda genes to entity_spec

  • Loading branch information...
PseudoKnight committed Oct 1, 2019
1 parent 9118c59 commit 6c596d9406b3674ea3244982463dedaf6c1a6cdf
@@ -0,0 +1,65 @@
package com.laytonsmith.abstraction.bukkit.entities;

import com.laytonsmith.abstraction.Implementation;
import com.laytonsmith.abstraction.entities.MCPanda;
import com.laytonsmith.abstraction.enums.EnumConvertor;
import com.laytonsmith.abstraction.enums.MCVersion;
import com.laytonsmith.annotations.abstractionenum;
import com.laytonsmith.core.Static;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Panda;

public class BukkitMCPanda extends BukkitMCAgeable implements MCPanda {

private Panda p;

public BukkitMCPanda(Entity be) {
super(be);
p = (Panda) be;
}

@Override
public Gene getMainGene() {
return MCPanda.Gene.valueOf(p.getMainGene().name());
}

@Override
public void setMainGene(Gene gene) {
p.setMainGene(Panda.Gene.valueOf(gene.name()));
}

@Override
public Gene getHiddenGene() {
return MCPanda.Gene.valueOf(p.getHiddenGene().name());
}

@Override
public void setHiddenGene(Gene gene) {
p.setHiddenGene(Panda.Gene.valueOf(gene.name()));
}

@abstractionenum(
implementation = Implementation.Type.BUKKIT,
forAbstractEnum = MCPanda.Gene.class,
forConcreteEnum = Panda.Gene.class
)
public static class BukkitMCPandaGene extends EnumConvertor<MCPanda.Gene, Panda.Gene> {

private static BukkitMCPandaGene instance;

public static BukkitMCPandaGene getConvertor() {
if(instance == null) {
instance = new BukkitMCPandaGene();
}
return instance;
}

@Override
protected Panda.Gene getConcreteEnumCustom(MCPanda.Gene abstracted) {
if(Static.getServer().getMinecraftVersion().lt(MCVersion.MC1_14)) {
return null;
}
return super.getConcreteEnumCustom(abstracted);
}
}
}
@@ -36,6 +36,44 @@ public void setProfession(MCProfession profession) {
getHandle().setProfession((Villager.Profession) profession.getConcrete());
}

@Override
public int getLevel() {
try {
return getHandle().getVillagerLevel();
} catch (NoSuchMethodError ex) {
// 1.13
return 1;
}
}

@Override
public void setLevel(int level) {
try {
getHandle().setVillagerLevel(level);
} catch (NoSuchMethodError ex) {
// 1.13
}
}

@Override
public int getExperience() {
try {
return getHandle().getVillagerExperience();
} catch (NoSuchMethodError ex) {
// 1.13
return 0;
}
}

@Override
public void setExperience(int exp) {
try {
getHandle().setVillagerExperience(exp);
} catch (NoSuchMethodError ex) {
// 1.13
}
}

@Override
public MCMerchant asMerchant() {
Villager villager = getHandle();
@@ -0,0 +1,17 @@
package com.laytonsmith.abstraction.entities;

import com.laytonsmith.annotations.MEnum;

public interface MCPanda extends MCAgeable {

@MEnum("com.commandhelper.PandaGene")
enum Gene {
AGGRESSIVE, BROWN, LAZY, NORMAL, PLAYFUL, WEAK, WORRIED
}

MCPanda.Gene getMainGene();
void setMainGene(Gene gene);
MCPanda.Gene getHiddenGene();
void setHiddenGene(Gene gene);

}
@@ -6,4 +6,8 @@

MCProfession getProfession();
void setProfession(MCProfession profession);
int getLevel();
void setLevel(int level);
int getExperience();
void setExperience(int exp);
}
@@ -56,6 +56,7 @@
import com.laytonsmith.abstraction.entities.MCMushroomCow;
import com.laytonsmith.abstraction.entities.MCOcelot;
import com.laytonsmith.abstraction.entities.MCPainting;
import com.laytonsmith.abstraction.entities.MCPanda;
import com.laytonsmith.abstraction.entities.MCParrot;
import com.laytonsmith.abstraction.entities.MCPig;
import com.laytonsmith.abstraction.entities.MCPigZombie;
@@ -1689,6 +1690,7 @@ public String docs() {
docs = docs.replace("%CAT_TYPE%", StringUtils.Join(MCCatType.values(), ", ", ", or ", " or "));
docs = docs.replace("%FOX_TYPE%", StringUtils.Join(MCFoxType.values(), ", ", ", or ", " or "));
docs = docs.replace("%MUSHROOM_COW_TYPE%", StringUtils.Join(MCMushroomCowType.values(), ", ", ", or ", " or "));
docs = docs.replace("%PANDA_GENE%", StringUtils.Join(MCPanda.Gene.values(), ", ", ", or ", " or "));
for(Field field : entity_spec.class.getDeclaredFields()) {
try {
String name = field.getName();
@@ -1934,6 +1936,11 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
MCPainting painting = (MCPainting) entity;
specArray.set(entity_spec.KEY_PAINTING_ART, new CString(painting.getArt().name(), t), t);
break;
case PANDA:
MCPanda panda = (MCPanda) entity;
specArray.set(entity_spec.KEY_PANDA_MAINGENE, new CString(panda.getMainGene().name(), t), t);
specArray.set(entity_spec.KEY_PANDA_HIDDENGENE, new CString(panda.getHiddenGene().name(), t), t);
break;
case PARROT:
MCParrot parrot = (MCParrot) entity;
specArray.set(entity_spec.KEY_GENERIC_SITTING, CBoolean.get(parrot.isSitting()), t);
@@ -2031,6 +2038,8 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
case VILLAGER:
MCVillager villager = (MCVillager) entity;
specArray.set(entity_spec.KEY_VILLAGER_PROFESSION, new CString(villager.getProfession().name(), t), t);
specArray.set(entity_spec.KEY_VILLAGER_LEVEL, new CInt(villager.getLevel(), t), t);
specArray.set(entity_spec.KEY_VILLAGER_EXPERIENCE, new CInt(villager.getExperience(), t), t);
break;
case WITHER_SKULL:
MCWitherSkull skull = (MCWitherSkull) entity;
@@ -2130,6 +2139,8 @@ public MSVersion since() {
private static final String KEY_MUSHROOM_COW_TYPE = "type";
private static final String KEY_OCELOT_TYPE = "type";
private static final String KEY_PAINTING_ART = "type";
private static final String KEY_PANDA_MAINGENE = "maingene";
private static final String KEY_PANDA_HIDDENGENE = "hiddengene";
private static final String KEY_PARROT_TYPE = "type";
private static final String KEY_PIG_SADDLED = "saddled";
private static final String KEY_PIG_ZOMBIE_ANGRY = "angry";
@@ -2150,6 +2161,8 @@ public MSVersion since() {
private static final String KEY_TROPICALFISH_PATTERN = "pattern";
private static final String KEY_TROPICALFISH_PATTERNCOLOR = "patterncolor";
private static final String KEY_VILLAGER_PROFESSION = "profession";
private static final String KEY_VILLAGER_LEVEL = "level";
private static final String KEY_VILLAGER_EXPERIENCE = "experience";
private static final String KEY_WITHER_SKULL_CHARGED = "charged";
private static final String KEY_WOLF_ANGRY = "angry";
private static final String KEY_WOLF_COLOR = "color";
@@ -2903,6 +2916,29 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
}
}
break;
case PANDA:
MCPanda panda = (MCPanda) entity;
for(String index : specArray.stringKeySet()) {
switch(index.toLowerCase()) {
case entity_spec.KEY_PANDA_MAINGENE:
try {
panda.setMainGene(MCPanda.Gene.valueOf(specArray.get(index, t).val().toUpperCase()));
} catch (IllegalArgumentException exception) {
throw new CREFormatException("Invalid panda gene: " + specArray.get(index, t).val(), t);
}
break;
case entity_spec.KEY_PANDA_HIDDENGENE:
try {
panda.setHiddenGene(MCPanda.Gene.valueOf(specArray.get(index, t).val().toUpperCase()));
} catch (IllegalArgumentException exception) {
throw new CREFormatException("Invalid panda gene: " + specArray.get(index, t).val(), t);
}
break;
default:
throwException(index, t);
}
}
break;
case PARROT:
MCParrot parrot = (MCParrot) entity;
for(String index : specArray.stringKeySet()) {
@@ -3242,6 +3278,22 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
throw new CREFormatException("Invalid profession: " + specArray.get(index, t).val(), t);
}
break;
case entity_spec.KEY_VILLAGER_LEVEL:
try {
villager.setLevel(Static.getInt32(specArray.get(index, t), t));
} catch (IllegalArgumentException exception) {
throw new CRERangeException("Expected profession level to be 1-5, but got "
+ specArray.get(index, t).val(), t);
}
break;
case entity_spec.KEY_VILLAGER_EXPERIENCE:
try {
villager.setExperience(Static.getInt32(specArray.get(index, t), t));
} catch (IllegalArgumentException exception) {
throw new CRERangeException("Expected experience to be a positive number, but got "
+ specArray.get(index, t).val(), t);
}
break;
default:
throwException(index, t);
}
@@ -180,6 +180,11 @@ without knowing the rotations on the other axis or of other body parts beforehan
|
* %KEY_PAINTING_ART%: The art on the painting (can be %ART%).
|-
| PANDA
|
* %KEY_PANDA_MAINGENE%: The dominant trait for this panda (can be %PANDA_GENE%).
* %KEY_PANDA_HIDDENGENE%: The recessive trait for this panda.
|-
| PARROT
|
* %KEY_GENERIC_SITTING%: If the parrot is sitting.
@@ -265,6 +270,8 @@ without knowing the rotations on the other axis or of other body parts beforehan
| VILLAGER
|
* %KEY_VILLAGER_PROFESSION%: The profession of the villager (can be %PROFESSION%). This list differs in 1.14 from 1.13.
* %KEY_VILLAGER_EXPERIENCE%: The amount of experience in the villager's profession towards the next level. (not in 1.13)
* %KEY_VILLAGER_LEVEL%: The level of villager's profession. Can be 1-5. (not in 1.13)
|-
| WITHER_SKULL
|

0 comments on commit 6c596d9

Please sign in to comment.
You can’t perform that action at this time.