Skip to content

Commit c56a9e6

Browse files
pop4959mdcfe
andauthored
Add spawnable boat variants (#5027)
Co-authored-by: MD <1917406+mdcfe@users.noreply.github.com>
1 parent 5b20f30 commit c56a9e6

2 files changed

Lines changed: 64 additions & 4 deletions

File tree

Essentials/src/main/java/com/earth2me/essentials/MobCompat.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import com.earth2me.essentials.utils.EnumUtil;
44
import com.earth2me.essentials.utils.VersionUtil;
55
import net.ess3.nms.refl.ReflUtil;
6+
import org.bukkit.TreeSpecies;
67
import org.bukkit.entity.Axolotl;
8+
import org.bukkit.entity.Boat;
79
import org.bukkit.entity.Entity;
810
import org.bukkit.entity.EntityType;
911
import org.bukkit.entity.Fox;
@@ -175,6 +177,24 @@ public static void setFrogVariant(final Entity entity, final String variant) {
175177
}
176178
}
177179

180+
public static void setBoatVariant(final Entity entity, final BoatVariant variant) {
181+
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_9_R01)) {
182+
return;
183+
}
184+
final Boat boat;
185+
if (entity instanceof Boat) {
186+
boat = (Boat) entity;
187+
} else {
188+
return;
189+
}
190+
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_19_R01)) {
191+
//noinspection deprecation
192+
boat.setWoodType(TreeSpecies.valueOf(variant.getTreeSpecies()));
193+
} else {
194+
boat.setBoatType(Boat.Type.valueOf(variant.getBoatType()));
195+
}
196+
}
197+
178198
public enum CatType {
179199
// These are (loosely) Mojang names for the cats
180200
SIAMESE("SIAMESE", "SIAMESE_CAT"),
@@ -239,4 +259,34 @@ private Villager.Profession asEnum() {
239259
}
240260
}
241261

262+
public enum BoatVariant {
263+
// Mappings for TreeSpecies names
264+
ACACIA("ACACIA", "ACACIA"),
265+
BIRCH("BIRCH", "BIRCH"),
266+
DARKOAK("DARK_OAK", "DARK_OAK"),
267+
GENERIC("GENERIC", "OAK"),
268+
JUNGLE("JUNGLE", "JUNGLE"),
269+
REDWOOD("REDWOOD", "SPRUCE"),
270+
// Mappings for Boat.Type names (falling back to GENERIC where undefined)
271+
OAK("GENERIC", "OAK"),
272+
SPRUCE("REDWOOD", "SPRUCE"),
273+
MANGROVE("GENERIC", "MANGROVE"),
274+
;
275+
276+
private final String treeSpecies;
277+
private final String boatType;
278+
279+
BoatVariant(final String treeSpecies, final String boatType) {
280+
this.treeSpecies = treeSpecies;
281+
this.boatType = boatType;
282+
}
283+
284+
public String getTreeSpecies() {
285+
return treeSpecies;
286+
}
287+
288+
public String getBoatType() {
289+
return boatType;
290+
}
291+
}
242292
}

Essentials/src/main/java/com/earth2me/essentials/MobData.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.bukkit.DyeColor;
88
import org.bukkit.Material;
99
import org.bukkit.entity.Ageable;
10+
import org.bukkit.entity.Boat;
1011
import org.bukkit.entity.ChestedHorse;
1112
import org.bukkit.entity.Creeper;
1213
import org.bukkit.entity.Entity;
@@ -199,6 +200,15 @@ public enum MobData {
199200
TEMPERATE_FROG("temperate", MobCompat.FROG, "frog:TEMPERATE", true),
200201
WARM_FROG("warm", MobCompat.FROG, "frog:WARM", true),
201202
COLD_FROG("cold", MobCompat.FROG, "frog:COLD", true),
203+
ACACIA_BOAT("acacia", Boat.class, MobCompat.BoatVariant.ACACIA, true),
204+
BIRCH_BOAT("birch", Boat.class, MobCompat.BoatVariant.BIRCH, true),
205+
DARK_OAK_BOAT("darkoak", Boat.class, MobCompat.BoatVariant.DARKOAK, true),
206+
GENERIC_BOAT("generic", Boat.class, MobCompat.BoatVariant.GENERIC, true),
207+
JUNGLE_BOAT("jungle", Boat.class, MobCompat.BoatVariant.JUNGLE, true),
208+
REDWOOD_BOAT("redwood", Boat.class, MobCompat.BoatVariant.REDWOOD, true),
209+
MANGROVE_BOAT("mangrove", Boat.class, MobCompat.BoatVariant.MANGROVE, true),
210+
OAK_BOAT("oak", Boat.class, MobCompat.BoatVariant.OAK, true),
211+
SPRUCE_BOAT("spruce", Boat.class, MobCompat.BoatVariant.SPRUCE, true),
202212
;
203213

204214
final private String nickname;
@@ -377,6 +387,8 @@ public void setData(final Entity spawned, final Player target, final String rawD
377387
}
378388
} else if (this.value.equals(Data.GOAT_SCREAMING)) {
379389
((Goat) spawned).setScreaming(true);
390+
} else if (this.value instanceof MobCompat.BoatVariant) {
391+
MobCompat.setBoatVariant(spawned, (MobCompat.BoatVariant) this.value);
380392
} else if (this.value instanceof String) {
381393
final String[] split = ((String) this.value).split(":");
382394
switch (split[0]) {
@@ -404,14 +416,12 @@ public void setData(final Entity spawned, final Player target, final String rawD
404416
case "fox":
405417
MobCompat.setFoxType(spawned, split[1]);
406418
break;
407-
case "axolotl": {
419+
case "axolotl":
408420
MobCompat.setAxolotlVariant(spawned, split[1]);
409421
break;
410-
}
411-
case "frog": {
422+
case "frog":
412423
MobCompat.setFrogVariant(spawned, split[1]);
413424
break;
414-
}
415425
}
416426
} else {
417427
Essentials.getWrappedLogger().warning("Unknown mob data type: " + this.toString());

0 commit comments

Comments
 (0)