Skip to content

Commit 4924b5d

Browse files
committed
Add boat "type" to entity_spec()
1 parent fbd63c0 commit 4924b5d

6 files changed

Lines changed: 113 additions & 3 deletions

File tree

src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCBoat.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.laytonsmith.abstraction.bukkit.entities;
22

33
import com.laytonsmith.abstraction.entities.MCBoat;
4+
import com.laytonsmith.abstraction.enums.MCTreeSpecies;
5+
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCTreeSpecies;
46
import org.bukkit.entity.Boat;
57
import org.bukkit.entity.Entity;
68

@@ -22,4 +24,19 @@ public double getMaxSpeed() {
2224
public void setMaxSpeed(double speed) {
2325
b.setMaxSpeed(speed);
2426
}
27+
28+
@Override
29+
public MCTreeSpecies getWoodType() {
30+
return BukkitMCTreeSpecies.getConvertor().getAbstractedEnum(b.getWoodType());
31+
}
32+
33+
@Override
34+
public void setWoodType(MCTreeSpecies type) {
35+
try {
36+
b.setWoodType(BukkitMCTreeSpecies.getConvertor().getConcreteEnum(type));
37+
} catch(NoSuchMethodError ex) {
38+
// probably prior to 1.9
39+
}
40+
}
41+
2542
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.laytonsmith.abstraction.entities;
22

33
import com.laytonsmith.abstraction.MCVehicle;
4+
import com.laytonsmith.abstraction.enums.MCTreeSpecies;
45

56
public interface MCBoat extends MCVehicle {
6-
77
double getMaxSpeed();
8-
98
void setMaxSpeed(double speed);
9+
MCTreeSpecies getWoodType();
10+
void setWoodType(MCTreeSpecies type);
1011
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.laytonsmith.abstraction.enums;
2+
3+
import com.laytonsmith.annotations.MEnum;
4+
5+
@MEnum("WoodType")
6+
public enum MCTreeSpecies {
7+
ACACIA,
8+
BIRCH,
9+
DARK_OAK,
10+
JUNGLE,
11+
OAK,
12+
SPRUCE
13+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.laytonsmith.abstraction.enums.bukkit;
2+
3+
import com.laytonsmith.abstraction.Implementation;
4+
import com.laytonsmith.abstraction.enums.EnumConvertor;
5+
import com.laytonsmith.abstraction.enums.MCTreeSpecies;
6+
import com.laytonsmith.annotations.abstractionenum;
7+
import org.bukkit.TreeSpecies;
8+
9+
@abstractionenum(
10+
implementation = Implementation.Type.BUKKIT,
11+
forAbstractEnum = MCTreeSpecies.class,
12+
forConcreteEnum = TreeSpecies.class
13+
)
14+
public class BukkitMCTreeSpecies extends EnumConvertor<MCTreeSpecies, TreeSpecies> {
15+
16+
private static BukkitMCTreeSpecies instance;
17+
18+
public static BukkitMCTreeSpecies getConvertor() {
19+
if(instance == null) {
20+
instance = new BukkitMCTreeSpecies();
21+
}
22+
return instance;
23+
}
24+
25+
@Override
26+
protected MCTreeSpecies getAbstractedEnumCustom(TreeSpecies concrete) {
27+
switch(concrete) {
28+
case GENERIC:
29+
return MCTreeSpecies.OAK;
30+
case REDWOOD:
31+
return MCTreeSpecies.SPRUCE;
32+
}
33+
return super.getAbstractedEnumCustom(concrete);
34+
}
35+
36+
@Override
37+
protected TreeSpecies getConcreteEnumCustom(MCTreeSpecies abstracted) {
38+
switch(abstracted) {
39+
case OAK:
40+
return TreeSpecies.GENERIC;
41+
case SPRUCE:
42+
return TreeSpecies.REDWOOD;
43+
}
44+
return super.getConcreteEnumCustom(abstracted);
45+
}
46+
}

src/main/java/com/laytonsmith/core/functions/EntityManagement.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import com.laytonsmith.abstraction.enums.MCRabbitType;
8888
import com.laytonsmith.abstraction.enums.MCRotation;
8989
import com.laytonsmith.abstraction.enums.MCSkeletonType;
90+
import com.laytonsmith.abstraction.enums.MCTreeSpecies;
9091
import com.laytonsmith.abstraction.enums.MCVersion;
9192
import com.laytonsmith.annotations.api;
9293
import com.laytonsmith.annotations.hide;
@@ -1738,6 +1739,7 @@ public String docs() {
17381739
docs = docs.replace("%RABBIT_TYPE%", StringUtils.Join(MCRabbitType.values(), ", ", ", or ", " or "));
17391740
docs = docs.replace("%PARTICLE%", StringUtils.Join(MCParticle.values(), ", ", ", or ", " or "));
17401741
docs = docs.replace("%ENDERDRAGON_PHASE%", StringUtils.Join(MCEnderDragonPhase.values(), ", ", ", or ", " or "));
1742+
docs = docs.replace("%TREE_SPECIES%", StringUtils.Join(MCTreeSpecies.values(), ", ", ", or ", " or "));
17411743
for(Field field : entity_spec.class.getDeclaredFields()) {
17421744
try {
17431745
String name = field.getName();
@@ -1807,6 +1809,12 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
18071809
}
18081810
specArray.set(entity_spec.KEY_ARMORSTAND_POSES, poses, t);
18091811
break;
1812+
case BOAT:
1813+
MCBoat boat = (MCBoat) entity;
1814+
if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_9)) {
1815+
specArray.set(entity_spec.KEY_BOAT_TYPE, new CString(boat.getWoodType().name(), t), t);
1816+
}
1817+
break;
18101818
case CREEPER:
18111819
MCCreeper creeper = (MCCreeper) entity;
18121820
specArray.set(entity_spec.KEY_CREEPER_POWERED, CBoolean.get(creeper.isPowered()), t);
@@ -2090,6 +2098,7 @@ public CHVersion since() {
20902098
private static final String KEY_ARMORSTAND_POSES = "poses";
20912099
private static final String KEY_ARMORSTAND_SMALLSIZE = "small";
20922100
private static final String KEY_ARMORSTAND_VISIBLE = "visible";
2101+
private static final String KEY_BOAT_TYPE = "type";
20932102
private static final String KEY_CREEPER_POWERED = "powered";
20942103
private static final String KEY_CREEPER_MAXFUSETICKS = "maxfuseticks";
20952104
private static final String KEY_CREEPER_EXPLOSIONRADIUS = "explosionradius";
@@ -2337,6 +2346,22 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
23372346
}
23382347
}
23392348
break;
2349+
case BOAT:
2350+
MCBoat boat = (MCBoat) entity;
2351+
for(String index : specArray.stringKeySet()) {
2352+
switch(index.toLowerCase()) {
2353+
case entity_spec.KEY_BOAT_TYPE:
2354+
try {
2355+
boat.setWoodType(MCTreeSpecies.valueOf(specArray.get(index, t).val().toUpperCase()));
2356+
} catch(IllegalArgumentException ex) {
2357+
throw new CREFormatException("Invalid boat type: " + specArray.get(index, t).val(), t);
2358+
}
2359+
break;
2360+
default:
2361+
throwException(index, t);
2362+
}
2363+
}
2364+
break;
23402365
case CREEPER:
23412366
MCCreeper creeper = (MCCreeper) entity;
23422367
for(String index : specArray.stringKeySet()) {
@@ -2439,7 +2464,11 @@ public Construct exec(Target t, Environment environment, Construct... args) thro
24392464
for(String index : specArray.stringKeySet()) {
24402465
switch(index.toLowerCase()) {
24412466
case entity_spec.KEY_ENDERDRAGON_PHASE:
2442-
enderdragon.setPhase(MCEnderDragonPhase.valueOf(specArray.get(index, t).val().toUpperCase()));
2467+
try {
2468+
enderdragon.setPhase(MCEnderDragonPhase.valueOf(specArray.get(index, t).val().toUpperCase()));
2469+
} catch(IllegalArgumentException ex) {
2470+
throw new CREFormatException("Invalid EnderDragon phase: " + specArray.get(index, t).val(), t);
2471+
}
24432472
break;
24442473
default:
24452474
throwException(index, t);

src/main/resources/functionDocs/entity_spec

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ relative to the default position (where all angles are 0). Setting these values
3838
where only values specified will be changed. This allows you to rotate a single body part around a single axis
3939
without knowing the rotations on the other axis or of other body parts beforehand.
4040
|-
41+
| BOAT
42+
|
43+
* %KEY_BOAT_TYPE%: Which tree species the boat is composed of. (can be %TREE_SPECIES%)
44+
|-
4145
| CREEPER
4246
|
4347
* %KEY_CREEPER_POWERED%: If the Creeper is powered or not.

0 commit comments

Comments
 (0)