Add spawnable boat variants (#5027)

Co-authored-by: MD <1917406+mdcfe@users.noreply.github.com>
This commit is contained in:
pop4959 2022-08-02 11:18:57 -07:00 committed by GitHub
parent 5b20f30350
commit c56a9e6741
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 4 deletions

View File

@ -3,7 +3,9 @@ package com.earth2me.essentials;
import com.earth2me.essentials.utils.EnumUtil; import com.earth2me.essentials.utils.EnumUtil;
import com.earth2me.essentials.utils.VersionUtil; import com.earth2me.essentials.utils.VersionUtil;
import net.ess3.nms.refl.ReflUtil; import net.ess3.nms.refl.ReflUtil;
import org.bukkit.TreeSpecies;
import org.bukkit.entity.Axolotl; import org.bukkit.entity.Axolotl;
import org.bukkit.entity.Boat;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Fox; import org.bukkit.entity.Fox;
@ -175,6 +177,24 @@ public final class MobCompat {
} }
} }
public static void setBoatVariant(final Entity entity, final BoatVariant variant) {
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_9_R01)) {
return;
}
final Boat boat;
if (entity instanceof Boat) {
boat = (Boat) entity;
} else {
return;
}
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_19_R01)) {
//noinspection deprecation
boat.setWoodType(TreeSpecies.valueOf(variant.getTreeSpecies()));
} else {
boat.setBoatType(Boat.Type.valueOf(variant.getBoatType()));
}
}
public enum CatType { public enum CatType {
// These are (loosely) Mojang names for the cats // These are (loosely) Mojang names for the cats
SIAMESE("SIAMESE", "SIAMESE_CAT"), SIAMESE("SIAMESE", "SIAMESE_CAT"),
@ -239,4 +259,34 @@ public final class MobCompat {
} }
} }
public enum BoatVariant {
// Mappings for TreeSpecies names
ACACIA("ACACIA", "ACACIA"),
BIRCH("BIRCH", "BIRCH"),
DARKOAK("DARK_OAK", "DARK_OAK"),
GENERIC("GENERIC", "OAK"),
JUNGLE("JUNGLE", "JUNGLE"),
REDWOOD("REDWOOD", "SPRUCE"),
// Mappings for Boat.Type names (falling back to GENERIC where undefined)
OAK("GENERIC", "OAK"),
SPRUCE("REDWOOD", "SPRUCE"),
MANGROVE("GENERIC", "MANGROVE"),
;
private final String treeSpecies;
private final String boatType;
BoatVariant(final String treeSpecies, final String boatType) {
this.treeSpecies = treeSpecies;
this.boatType = boatType;
}
public String getTreeSpecies() {
return treeSpecies;
}
public String getBoatType() {
return boatType;
}
}
} }

View File

@ -7,6 +7,7 @@ import com.earth2me.essentials.utils.VersionUtil;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Ageable; import org.bukkit.entity.Ageable;
import org.bukkit.entity.Boat;
import org.bukkit.entity.ChestedHorse; import org.bukkit.entity.ChestedHorse;
import org.bukkit.entity.Creeper; import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@ -199,6 +200,15 @@ public enum MobData {
TEMPERATE_FROG("temperate", MobCompat.FROG, "frog:TEMPERATE", true), TEMPERATE_FROG("temperate", MobCompat.FROG, "frog:TEMPERATE", true),
WARM_FROG("warm", MobCompat.FROG, "frog:WARM", true), WARM_FROG("warm", MobCompat.FROG, "frog:WARM", true),
COLD_FROG("cold", MobCompat.FROG, "frog:COLD", true), COLD_FROG("cold", MobCompat.FROG, "frog:COLD", true),
ACACIA_BOAT("acacia", Boat.class, MobCompat.BoatVariant.ACACIA, true),
BIRCH_BOAT("birch", Boat.class, MobCompat.BoatVariant.BIRCH, true),
DARK_OAK_BOAT("darkoak", Boat.class, MobCompat.BoatVariant.DARKOAK, true),
GENERIC_BOAT("generic", Boat.class, MobCompat.BoatVariant.GENERIC, true),
JUNGLE_BOAT("jungle", Boat.class, MobCompat.BoatVariant.JUNGLE, true),
REDWOOD_BOAT("redwood", Boat.class, MobCompat.BoatVariant.REDWOOD, true),
MANGROVE_BOAT("mangrove", Boat.class, MobCompat.BoatVariant.MANGROVE, true),
OAK_BOAT("oak", Boat.class, MobCompat.BoatVariant.OAK, true),
SPRUCE_BOAT("spruce", Boat.class, MobCompat.BoatVariant.SPRUCE, true),
; ;
final private String nickname; final private String nickname;
@ -377,6 +387,8 @@ public enum MobData {
} }
} else if (this.value.equals(Data.GOAT_SCREAMING)) { } else if (this.value.equals(Data.GOAT_SCREAMING)) {
((Goat) spawned).setScreaming(true); ((Goat) spawned).setScreaming(true);
} else if (this.value instanceof MobCompat.BoatVariant) {
MobCompat.setBoatVariant(spawned, (MobCompat.BoatVariant) this.value);
} else if (this.value instanceof String) { } else if (this.value instanceof String) {
final String[] split = ((String) this.value).split(":"); final String[] split = ((String) this.value).split(":");
switch (split[0]) { switch (split[0]) {
@ -404,14 +416,12 @@ public enum MobData {
case "fox": case "fox":
MobCompat.setFoxType(spawned, split[1]); MobCompat.setFoxType(spawned, split[1]);
break; break;
case "axolotl": { case "axolotl":
MobCompat.setAxolotlVariant(spawned, split[1]); MobCompat.setAxolotlVariant(spawned, split[1]);
break; break;
} case "frog":
case "frog": {
MobCompat.setFrogVariant(spawned, split[1]); MobCompat.setFrogVariant(spawned, split[1]);
break; break;
}
} }
} else { } else {
Essentials.getWrappedLogger().warning("Unknown mob data type: " + this.toString()); Essentials.getWrappedLogger().warning("Unknown mob data type: " + this.toString());