Permalink
Browse files

Add Tropical Fish entity_spec() and bucket item meta

  • Loading branch information...
PseudoKnight committed Aug 15, 2018
1 parent 45b113d commit 31bf10f59c13c425a5730db358a86dd464453c7c
@@ -0,0 +1,16 @@
package com.laytonsmith.abstraction;
import com.laytonsmith.abstraction.entities.MCTropicalFish;
import com.laytonsmith.abstraction.enums.MCDyeColor;
public interface MCTropicalFishBucketMeta extends MCItemMeta {
MCDyeColor getPatternColor();
void setPatternColor(MCDyeColor color);
MCDyeColor getBodyColor();
void setBodyColor(MCDyeColor color);
MCTropicalFish.MCPattern getPattern();
void setPattern(MCTropicalFish.MCPattern pattern);
boolean hasVariant();
}
@@ -134,6 +134,7 @@
import org.bukkit.inventory.meta.MapMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.inventory.meta.TropicalFishBucketMeta;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.potion.PotionData;
import org.yaml.snakeyaml.Yaml;
@@ -564,6 +565,9 @@ public static MCItemMeta BukkitGetCorrectMeta(ItemMeta im) {
if(im instanceof MapMeta) {
return new BukkitMCMapMeta((MapMeta) im);
}
if(im instanceof TropicalFishBucketMeta) {
return new BukkitMCTropicalFishBucketMeta((TropicalFishBucketMeta) im);
}
return new BukkitMCItemMeta(im);
}
@@ -0,0 +1,53 @@
package com.laytonsmith.abstraction.bukkit;
import com.laytonsmith.abstraction.MCTropicalFishBucketMeta;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCTropicalFish;
import com.laytonsmith.abstraction.entities.MCTropicalFish;
import com.laytonsmith.abstraction.enums.MCDyeColor;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCDyeColor;
import org.bukkit.inventory.meta.TropicalFishBucketMeta;
public class BukkitMCTropicalFishBucketMeta extends BukkitMCItemMeta implements MCTropicalFishBucketMeta {
TropicalFishBucketMeta meta;
public BukkitMCTropicalFishBucketMeta(TropicalFishBucketMeta im) {
super(im);
meta = im;
}
@Override
public MCDyeColor getPatternColor() {
return BukkitMCDyeColor.getConvertor().getAbstractedEnum(meta.getPatternColor());
}
@Override
public void setPatternColor(MCDyeColor color) {
meta.setPatternColor(BukkitMCDyeColor.getConvertor().getConcreteEnum(color));
}
@Override
public MCDyeColor getBodyColor() {
return BukkitMCDyeColor.getConvertor().getAbstractedEnum(meta.getBodyColor());
}
@Override
public void setBodyColor(MCDyeColor color) {
meta.setBodyColor(BukkitMCDyeColor.getConvertor().getConcreteEnum(color));
}
@Override
public MCTropicalFish.MCPattern getPattern() {
return BukkitMCTropicalFish.BukkitMCPattern.getConvertor().getAbstractedEnum(meta.getPattern());
}
@Override
public void setPattern(MCTropicalFish.MCPattern pattern) {
meta.setPattern(BukkitMCTropicalFish.BukkitMCPattern.getConvertor().getConcreteEnum(pattern));
}
@Override
public boolean hasVariant() {
return meta.hasVariant();
}
}
@@ -597,10 +597,7 @@ public CArray spawnMob(MCMobs name, String subClass, int qty, MCLocation l, Targ
case SKELETON:
mobType = Skeleton.class;
if(!(subClass.isEmpty())) {
String type = "";
for(String st : subTypes) {
type = st;
}
String type = subTypes[subTypes.length - 1];
if(type.equals("WITHER")) {
mobType = WitherSkeleton.class;
} else if(type.equals("STRAY")) {
@@ -0,0 +1,67 @@
package com.laytonsmith.abstraction.bukkit.entities;
import com.laytonsmith.abstraction.Implementation;
import com.laytonsmith.abstraction.entities.MCTropicalFish;
import com.laytonsmith.abstraction.enums.EnumConvertor;
import com.laytonsmith.abstraction.enums.MCDyeColor;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCDyeColor;
import com.laytonsmith.annotations.abstractionenum;
import org.bukkit.entity.Entity;
import org.bukkit.entity.TropicalFish;
public class BukkitMCTropicalFish extends BukkitMCLivingEntity implements MCTropicalFish {
TropicalFish entity;
public BukkitMCTropicalFish(Entity be) {
super(be);
this.entity = (TropicalFish) be;
}
@Override
public MCDyeColor getPatternColor() {
return BukkitMCDyeColor.getConvertor().getAbstractedEnum(entity.getPatternColor());
}
@Override
public void setPatternColor(MCDyeColor color) {
entity.setPatternColor(BukkitMCDyeColor.getConvertor().getConcreteEnum(color));
}
@Override
public MCDyeColor getBodyColor() {
return BukkitMCDyeColor.getConvertor().getAbstractedEnum(entity.getBodyColor());
}
@Override
public void setBodyColor(MCDyeColor color) {
entity.setBodyColor(BukkitMCDyeColor.getConvertor().getConcreteEnum(color));
}
@Override
public MCPattern getPattern() {
return BukkitMCPattern.getConvertor().getAbstractedEnum(entity.getPattern());
}
@Override
public void setPattern(MCPattern pattern) {
entity.setPattern(BukkitMCPattern.getConvertor().getConcreteEnum(pattern));
}
@abstractionenum(
implementation = Implementation.Type.BUKKIT,
forAbstractEnum = MCPattern.class,
forConcreteEnum = TropicalFish.Pattern.class
)
public static class BukkitMCPattern extends EnumConvertor<MCPattern, TropicalFish.Pattern> {
private static BukkitMCPattern instance;
public static BukkitMCPattern getConvertor() {
if(instance == null) {
instance = new BukkitMCPattern();
}
return instance;
}
}
}
@@ -0,0 +1,32 @@
package com.laytonsmith.abstraction.entities;
import com.laytonsmith.abstraction.MCLivingEntity;
import com.laytonsmith.abstraction.enums.MCDyeColor;
import com.laytonsmith.annotations.MEnum;
public interface MCTropicalFish extends MCLivingEntity {
MCDyeColor getPatternColor();
void setPatternColor(MCDyeColor color);
MCDyeColor getBodyColor();
void setBodyColor(MCDyeColor color);
MCTropicalFish.MCPattern getPattern();
void setPattern(MCTropicalFish.MCPattern pattern);
@MEnum("TropicalFishPattern")
enum MCPattern {
KOB,
SUNSTREAK,
SNOOPER,
DASHER,
BRINELY,
SPOTTY,
FLOPPER,
STRIPEY,
GLITTER,
BLOCKFISH,
BETTY,
CLAYFISH
}
}
@@ -33,6 +33,7 @@
import com.laytonsmith.abstraction.MCShapedRecipe;
import com.laytonsmith.abstraction.MCShapelessRecipe;
import com.laytonsmith.abstraction.MCSkullMeta;
import com.laytonsmith.abstraction.MCTropicalFishBucketMeta;
import com.laytonsmith.abstraction.MCWorld;
import com.laytonsmith.abstraction.StaticLayer;
import com.laytonsmith.abstraction.blocks.MCBlockState;
@@ -45,14 +46,14 @@
import com.laytonsmith.abstraction.blocks.MCFurnace;
import com.laytonsmith.abstraction.blocks.MCHopper;
import com.laytonsmith.abstraction.blocks.MCShulkerBox;
import com.laytonsmith.abstraction.entities.MCTropicalFish;
import com.laytonsmith.abstraction.enums.MCDyeColor;
import com.laytonsmith.abstraction.enums.MCEntityType;
import com.laytonsmith.abstraction.enums.MCFireworkType;
import com.laytonsmith.abstraction.enums.MCItemFlag;
import com.laytonsmith.abstraction.enums.MCPatternShape;
import com.laytonsmith.abstraction.enums.MCPotionType;
import com.laytonsmith.abstraction.enums.MCRecipeType;
import com.laytonsmith.abstraction.enums.MCVersion;
import com.laytonsmith.core.constructs.CArray;
import com.laytonsmith.core.constructs.CBoolean;
import com.laytonsmith.core.constructs.CDouble;
@@ -558,10 +559,6 @@ public Construct itemMeta(MCItemStack is, Target t) {
patterns.push(pattern, t);
}
ma.set("patterns", patterns, t);
MCDyeColor dyeColor = bannermeta.getBaseColor();
if(dyeColor != null) {
ma.set("basecolor", new CString(dyeColor.toString(), t), t);
}
} else if(meta instanceof MCMapMeta) {
MCMapMeta mm = ((MCMapMeta) meta);
MCColor mapcolor = mm.getColor();
@@ -575,6 +572,17 @@ public Construct itemMeta(MCItemStack is, Target t) {
} else {
ma.set("mapid", CNull.NULL, t);
}
} else if(meta instanceof MCTropicalFishBucketMeta) {
MCTropicalFishBucketMeta fm = (MCTropicalFishBucketMeta) meta;
if(fm.hasVariant()) {
ma.set("fishcolor", new CString(fm.getBodyColor().name(), t), t);
ma.set("fishpatterncolor", new CString(fm.getPatternColor().name(), t), t);
ma.set("fishpattern", new CString(fm.getPattern().name(), t), t);
} else {
ma.set("fishcolor", CNull.NULL, t);
ma.set("fishpatterncolor", CNull.NULL, t);
ma.set("fishpattern", CNull.NULL, t);
}
}
return ma;
}
@@ -885,9 +893,6 @@ public MCItemMeta itemMeta(Construct c, MCMaterial mat, Target t) throws ConfigR
}
}
} else if(meta instanceof MCBannerMeta) {
if(ma.containsKey("basecolor")) {
((MCBannerMeta) meta).setBaseColor(MCDyeColor.valueOf(ma.get("basecolor", t).val().toUpperCase()));
}
if(ma.containsKey("patterns")) {
CArray array = ArgumentValidation.getArray(ma.get("patterns", t), t);
for(String key : array.stringKeySet()) {
@@ -897,7 +902,7 @@ public MCItemMeta itemMeta(Construct c, MCMaterial mat, Target t) throws ConfigR
((MCBannerMeta) meta).addPattern(StaticLayer.GetConvertor().GetPattern(color, shape));
}
}
} else if(meta instanceof MCMapMeta && Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_11)) {
} else if(meta instanceof MCMapMeta) {
if(ma.containsKey("color")) {
Construct ci = ma.get("color", t);
if(ci instanceof CArray) {
@@ -912,6 +917,28 @@ public MCItemMeta itemMeta(Construct c, MCMaterial mat, Target t) throws ConfigR
((MCMapMeta) meta).setMapId(Static.getInt32(cid, t));
}
}
} else if(meta instanceof MCTropicalFishBucketMeta) {
if(ma.containsKey("fishpatterncolor")) {
Construct patterncolor = ma.get("fishpatterncolor", t);
if(!(patterncolor instanceof CNull)) {
MCDyeColor color = MCDyeColor.valueOf(patterncolor.val().toUpperCase());
((MCTropicalFishBucketMeta) meta).setPatternColor(color);
}
}
if(ma.containsKey("fishcolor")) {
Construct fishcolor = ma.get("fishcolor", t);
if(!(fishcolor instanceof CNull)) {
MCDyeColor color = MCDyeColor.valueOf(fishcolor.val().toUpperCase());
((MCTropicalFishBucketMeta) meta).setBodyColor(color);
}
}
if(ma.containsKey("fishpattern")) {
Construct pa = ma.get("fishpattern", t);
if(!(pa instanceof CNull)) {
MCTropicalFish.MCPattern pattern = MCTropicalFish.MCPattern.valueOf(pa.val().toUpperCase());
((MCTropicalFishBucketMeta) meta).setPattern(pattern);
}
}
}
} catch (Exception ex) {
throw new CREFormatException(ex.getMessage(), t, ex);
@@ -66,6 +66,7 @@
import com.laytonsmith.abstraction.entities.MCTameable;
import com.laytonsmith.abstraction.entities.MCThrownPotion;
import com.laytonsmith.abstraction.entities.MCTippedArrow;
import com.laytonsmith.abstraction.entities.MCTropicalFish;
import com.laytonsmith.abstraction.entities.MCVillager;
import com.laytonsmith.abstraction.entities.MCWitherSkull;
import com.laytonsmith.abstraction.entities.MCWolf;
@@ -1678,6 +1679,7 @@ public String docs() {
docs = docs.replace("%PARTICLE%", StringUtils.Join(MCParticle.types(), ", ", ", or ", " or "));
docs = docs.replace("%ENDERDRAGON_PHASE%", StringUtils.Join(MCEnderDragonPhase.values(), ", ", ", or ", " or "));
docs = docs.replace("%TREE_SPECIES%", StringUtils.Join(MCTreeSpecies.values(), ", ", ", or ", " or "));
docs = docs.replace("%FISH_PATTERN%", StringUtils.Join(MCTropicalFish.MCPattern.values(), ", ", ", or ", " or "));
for(Field field : entity_spec.class.getDeclaredFields()) {
try {
String name = field.getName();
@@ -1962,6 +1964,12 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
tippedmeta.set("base", ObjectGenerator.GetGenerator().potionData(tippedarrow.getBasePotionData(), t), t);
specArray.set(entity_spec.KEY_TIPPEDARROW_POTIONMETA, tippedmeta, t);
break;
case TROPICAL_FISH:
MCTropicalFish fish = (MCTropicalFish) entity;
specArray.set(entity_spec.KEY_TROPICALFISH_COLOR, new CString(fish.getBodyColor().name(), t), t);
specArray.set(entity_spec.KEY_TROPICALFISH_PATTERN, new CString(fish.getPattern().name(), t), t);
specArray.set(entity_spec.KEY_TROPICALFISH_PATTERNCOLOR, new CString(fish.getPatternColor().name(), t), t);
break;
case VILLAGER:
MCVillager villager = (MCVillager) entity;
specArray.set(entity_spec.KEY_VILLAGER_PROFESSION, new CString(villager.getProfession().name(), t), t);
@@ -2070,6 +2078,9 @@ public CHVersion since() {
private static final String KEY_SNOWMAN_DERP = "derp";
private static final String KEY_SPLASH_POTION_ITEM = "item";
private static final String KEY_TIPPEDARROW_POTIONMETA = "potionmeta";
private static final String KEY_TROPICALFISH_COLOR = "color";
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_WITHER_SKULL_CHARGED = "charged";
private static final String KEY_WOLF_ANGRY = "angry";
@@ -2943,6 +2954,36 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
}
}
break;
case TROPICAL_FISH:
MCTropicalFish fish = (MCTropicalFish) entity;
for(String index : specArray.stringKeySet()) {
switch(index.toLowerCase()) {
case entity_spec.KEY_TROPICALFISH_COLOR:
try {
fish.setBodyColor(MCDyeColor.valueOf(specArray.get(index, t).val().toUpperCase()));
} catch (IllegalArgumentException exception) {
throw new CREFormatException("Invalid fish color: " + specArray.get(index, t).val(), t);
}
break;
case entity_spec.KEY_TROPICALFISH_PATTERNCOLOR:
try {
fish.setPatternColor(MCDyeColor.valueOf(specArray.get(index, t).val().toUpperCase()));
} catch (IllegalArgumentException exception) {
throw new CREFormatException("Invalid fish pattern color: " + specArray.get(index, t).val(), t);
}
break;
case entity_spec.KEY_TROPICALFISH_PATTERN:
try {
fish.setPattern(MCTropicalFish.MCPattern.valueOf(specArray.get(index, t).val().toUpperCase()));
} catch (IllegalArgumentException exception) {
throw new CREFormatException("Invalid fish pattern: " + specArray.get(index, t).val(), t);
}
break;
default:
throwException(index, t);
}
}
break;
case VILLAGER:
MCVillager villager = (MCVillager) entity;
for(String index : specArray.stringKeySet()) {
Oops, something went wrong.

0 comments on commit 31bf10f

Please sign in to comment.