Commit ea8e4aa7 authored by Ash's avatar Ash
Browse files

Added `LeashBone` option for MEG accessories for making things like ballons,...

Added `LeashBone` option for MEG accessories for making things like ballons, takes the name of a MEG leash bone to leash to
parent bde40849
...@@ -18,6 +18,7 @@ import java.util.Map; ...@@ -18,6 +18,7 @@ import java.util.Map;
public class CosmeticType { public class CosmeticType {
private static final Map<Class<? extends Cosmetic>, CosmeticConstant> constants = new HashMap<>(); private static final Map<Class<? extends Cosmetic>, CosmeticConstant> constants = new HashMap<>();
private static final Map<String, Class<? extends Cosmetic>> lookupByType = new HashMap<>();
static { static {
register(BackAccessory.class, new CosmeticConstant("BACK", "backs")); register(BackAccessory.class, new CosmeticConstant("BACK", "backs"));
...@@ -34,6 +35,11 @@ public class CosmeticType { ...@@ -34,6 +35,11 @@ public class CosmeticType {
public static void register(Class<? extends Cosmetic> clazz, CosmeticConstant cosmeticConstant) { public static void register(Class<? extends Cosmetic> clazz, CosmeticConstant cosmeticConstant) {
constants.put(clazz, cosmeticConstant); constants.put(clazz, cosmeticConstant);
lookupByType.put(cosmeticConstant.type(), clazz);
}
public static Class<? extends Cosmetic> get(String type) {
return lookupByType.get(type);
} }
public static CosmeticConstant get(Class<? extends Cosmetic> tClass) { public static CosmeticConstant get(Class<? extends Cosmetic> tClass) {
......
...@@ -6,6 +6,7 @@ import io.lumine.cosmetics.config.Scope; ...@@ -6,6 +6,7 @@ import io.lumine.cosmetics.config.Scope;
import io.lumine.cosmetics.constants.CosmeticType; import io.lumine.cosmetics.constants.CosmeticType;
import io.lumine.cosmetics.types.AbstractCosmetic; import io.lumine.cosmetics.types.AbstractCosmetic;
import io.lumine.mythic.bukkit.utils.config.properties.Property; import io.lumine.mythic.bukkit.utils.config.properties.Property;
import io.lumine.mythic.bukkit.utils.config.properties.types.BooleanProp;
import io.lumine.mythic.bukkit.utils.config.properties.types.EnumProp; import io.lumine.mythic.bukkit.utils.config.properties.types.EnumProp;
import io.lumine.mythic.bukkit.utils.config.properties.types.OrientProp; import io.lumine.mythic.bukkit.utils.config.properties.types.OrientProp;
import io.lumine.mythic.bukkit.utils.config.properties.types.StringProp; import io.lumine.mythic.bukkit.utils.config.properties.types.StringProp;
...@@ -21,11 +22,14 @@ public class MEGAccessory extends AbstractCosmetic implements ColorableCosmetic ...@@ -21,11 +22,14 @@ public class MEGAccessory extends AbstractCosmetic implements ColorableCosmetic
private static final StringProp STATE = Property.String(Scope.NONE, "State"); private static final StringProp STATE = Property.String(Scope.NONE, "State");
private static final OrientProp OFFSET = Property.Orient(Scope.NONE, "Offset"); private static final OrientProp OFFSET = Property.Orient(Scope.NONE, "Offset");
private static final EnumProp<ModelAnchor> MODELANCHOR = Property.Enum(Scope.NONE, ModelAnchor.class, "Anchor", ModelAnchor.BODY); private static final EnumProp<ModelAnchor> MODELANCHOR = Property.Enum(Scope.NONE, ModelAnchor.class, "Anchor", ModelAnchor.BODY);
private static final StringProp LEASH = Property.String(Scope.NONE, "LeashBone", null);
@Getter private final String modelId; @Getter private final String modelId;
@Getter private final String state; @Getter private final String state;
@Getter private final Orient offset; @Getter private final Orient offset;
@Getter private final ModelAnchor anchor; @Getter private final ModelAnchor anchor;
@Getter private final boolean leashed;
@Getter private final String leashBone;
public MEGAccessory(MEGManager manager, File file, String key) { public MEGAccessory(MEGManager manager, File file, String key) {
super(manager, file, CosmeticType.type(MEGAccessory.class), key); super(manager, file, CosmeticType.type(MEGAccessory.class), key);
...@@ -34,6 +38,13 @@ public class MEGAccessory extends AbstractCosmetic implements ColorableCosmetic ...@@ -34,6 +38,13 @@ public class MEGAccessory extends AbstractCosmetic implements ColorableCosmetic
state = STATE.fget(file, this); state = STATE.fget(file, this);
offset = OFFSET.fget(file, this); offset = OFFSET.fget(file, this);
anchor = MODELANCHOR.fget(file, this); anchor = MODELANCHOR.fget(file, this);
leashBone = LEASH.fget(file, this);
if(leashBone != null) {
leashed = true;
} else {
leashed = false;
}
} }
@Override @Override
......
...@@ -141,25 +141,21 @@ public class MEGManager extends MCCosmeticsManager<MEGAccessory> { ...@@ -141,25 +141,21 @@ public class MEGManager extends MCCosmeticsManager<MEGAccessory> {
public void equip(CosmeticProfile profile) { public void equip(CosmeticProfile profile) {
final var maybeEquipped = profile.getEquipped(MEGAccessory.class); final var maybeEquipped = profile.getEquipped(MEGAccessory.class);
if(maybeEquipped.isEmpty()) { if(maybeEquipped.isEmpty()) {
Log.info("No Accessory Found");
return; return;
} }
var opt = maybeEquipped.get().getCosmetic(); var opt = maybeEquipped.get().getCosmetic();
if(!(opt instanceof MEGAccessory meg)) { if(!(opt instanceof MEGAccessory meg)) {
Log.info("Accessory Invalid");
return; return;
} }
final var blueprint = ModelEngineAPI.getBlueprint(meg.getModelId()); final var blueprint = ModelEngineAPI.getBlueprint(meg.getModelId());
if(blueprint == null) { if(blueprint == null) {
Log.info("No Blueprint Found");
return; return;
} }
final var animation = blueprint.getAnimations().get(meg.getState()); final var animation = blueprint.getAnimations().get(meg.getState());
if(animation == null) { if(animation == null) {
Log.info("No Animation Found");
return; return;
} }
...@@ -177,7 +173,10 @@ public class MEGManager extends MCCosmeticsManager<MEGAccessory> { ...@@ -177,7 +173,10 @@ public class MEGManager extends MCCosmeticsManager<MEGAccessory> {
modeledEntity.destroy(); modeledEntity.destroy();
} }
modeledEntity = ModelEngineAPI.createModeledEntity(new FakeEntity(player, meg.getOffset(), meg.getAnchor())); final var fakeEntity = new FakeEntity(player, meg.getOffset(), meg.getAnchor());
fakeEntity.setCollidableWith(player, false);
modeledEntity = ModelEngineAPI.createModeledEntity(fakeEntity);
modeledEntity.getBase().getBodyRotationController().setPlayerMode(true); modeledEntity.getBase().getBodyRotationController().setPlayerMode(true);
modeledEntity.setBaseEntityVisible(true); modeledEntity.setBaseEntityVisible(true);
ModelEngineAPI.getEntityHandler().setForcedInvisible(player, false); ModelEngineAPI.getEntityHandler().setForcedInvisible(player, false);
...@@ -187,6 +186,13 @@ public class MEGManager extends MCCosmeticsManager<MEGAccessory> { ...@@ -187,6 +186,13 @@ public class MEGManager extends MCCosmeticsManager<MEGAccessory> {
} }
modeledEntity.addModel(activeModel, false).ifPresent(ActiveModel::destroy); modeledEntity.addModel(activeModel, false).ifPresent(ActiveModel::destroy);
if(meg.isLeashed()) {
activeModel.getLeashManager().ifPresent(leashManager -> {
leashManager.connectLeash(player, meg.getLeashBone());
});
}
} }
public void unequip(CosmeticProfile profile) { public void unequip(CosmeticProfile profile) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment