mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 16:24:23 +01:00
Port the gears to mson
This commit is contained in:
parent
c9e83bb131
commit
032fb2719f
8 changed files with 52 additions and 47 deletions
|
@ -29,10 +29,12 @@ import com.minelittlepony.client.model.gear.Stetson;
|
||||||
import com.minelittlepony.client.model.gear.WitchHat;
|
import com.minelittlepony.client.model.gear.WitchHat;
|
||||||
import com.minelittlepony.client.render.entity.RenderPonyPlayer;
|
import com.minelittlepony.client.render.entity.RenderPonyPlayer;
|
||||||
import com.minelittlepony.client.render.entity.RenderSeaponyPlayer;
|
import com.minelittlepony.client.render.entity.RenderSeaponyPlayer;
|
||||||
|
import com.minelittlepony.model.gear.IGear;
|
||||||
import com.minelittlepony.mson.api.ModelKey;
|
import com.minelittlepony.mson.api.ModelKey;
|
||||||
import com.minelittlepony.mson.api.Mson;
|
import com.minelittlepony.mson.api.Mson;
|
||||||
import com.minelittlepony.mson.api.MsonModel;
|
import com.minelittlepony.mson.api.MsonModel;
|
||||||
import com.minelittlepony.pony.meta.Race;
|
import com.minelittlepony.pony.meta.Race;
|
||||||
|
import com.minelittlepony.pony.meta.Wearable;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -40,10 +42,12 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public final class ModelType {
|
public final class ModelType {
|
||||||
|
|
||||||
private static final Map<Race, PlayerModelKey<?, ?>> PLAYER_MODELS = new HashMap<>();
|
private static final Map<Race, PlayerModelKey<?, ?>> PLAYER_MODELS = new HashMap<>();
|
||||||
|
private static final Map<Wearable, ModelKey<? extends IGear>> GEAR_MODELS = new HashMap<>();
|
||||||
|
|
||||||
public static final ModelKey<ModelVillagerPony<?>> VILLAGER = register("villager", ModelVillagerPony::new);
|
public static final ModelKey<ModelVillagerPony<?>> VILLAGER = register("villager", ModelVillagerPony::new);
|
||||||
public static final ModelKey<ModelWitchPony> WITCH = register("witch", ModelWitchPony::new);
|
public static final ModelKey<ModelWitchPony> WITCH = register("witch", ModelWitchPony::new);
|
||||||
|
@ -61,11 +65,11 @@ public final class ModelType {
|
||||||
public static final ModelKey<ModelPonyArmour<?>> ARMOUR_INNER = register("armour_inner", ModelPonyArmour::new);
|
public static final ModelKey<ModelPonyArmour<?>> ARMOUR_INNER = register("armour_inner", ModelPonyArmour::new);
|
||||||
public static final ModelKey<ModelPonyArmour<?>> ARMOUR_OUTER = register("armour_outer", ModelPonyArmour::new);
|
public static final ModelKey<ModelPonyArmour<?>> ARMOUR_OUTER = register("armour_outer", ModelPonyArmour::new);
|
||||||
|
|
||||||
public static final ModelKey<Stetson> STETSON = registerGear("stetson", Stetson::new);
|
public static final ModelKey<Stetson> STETSON = registerGear("stetson", Wearable.STETSON, Stetson::new);
|
||||||
public static final ModelKey<SaddleBags> SADDLEBAGS = registerGear("saddlebags", SaddleBags::new);
|
public static final ModelKey<SaddleBags> SADDLEBAGS = registerGear("saddlebags", Wearable.SADDLE_BAGS, SaddleBags::new);
|
||||||
public static final ModelKey<Muffin> MUFFIN = registerGear("muffin", Muffin::new);
|
public static final ModelKey<Muffin> MUFFIN = registerGear("muffin", Wearable.MUFFIN, Muffin::new);
|
||||||
public static final ModelKey<WitchHat> WITCH_HAT = registerGear("witch_hat", WitchHat::new);
|
public static final ModelKey<WitchHat> WITCH_HAT = registerGear("witch_hat", Wearable.HAT, WitchHat::new);
|
||||||
public static final ModelKey<ChristmasHat> ANTLERS = registerGear("antlers", ChristmasHat::new);
|
public static final ModelKey<ChristmasHat> ANTLERS = registerGear("antlers", Wearable.ANTLERS, ChristmasHat::new);
|
||||||
|
|
||||||
public static final PlayerModelKey<?, ModelAlicorn<?>> ALICORN = registerPlayer("alicorn", Race.ALICORN, ModelAlicorn::new);
|
public static final PlayerModelKey<?, ModelAlicorn<?>> ALICORN = registerPlayer("alicorn", Race.ALICORN, ModelAlicorn::new);
|
||||||
public static final PlayerModelKey<?, ModelUnicorn<?>> UNICORN = registerPlayer("unicorn", Race.UNICORN, ModelUnicorn::new);
|
public static final PlayerModelKey<?, ModelUnicorn<?>> UNICORN = registerPlayer("unicorn", Race.UNICORN, ModelUnicorn::new);
|
||||||
|
@ -91,8 +95,11 @@ public final class ModelType {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static <T extends Model & MsonModel> ModelKey<T> registerGear(String name, Supplier<T> constructor) {
|
@SuppressWarnings("unchecked")
|
||||||
return register("gear/" + name, constructor);
|
static <T extends IGear> ModelKey<T> registerGear(String name, Wearable wearable, Supplier<T> constructor) {
|
||||||
|
return (ModelKey<T>)GEAR_MODELS.computeIfAbsent(wearable, w -> {
|
||||||
|
return Mson.getInstance().registerModel(new Identifier("minelittlepony", "gear/" + name), constructor);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static <T extends Model & MsonModel> ModelKey<T> register(String name, Supplier<T> constructor) {
|
static <T extends Model & MsonModel> ModelKey<T> register(String name, Supplier<T> constructor) {
|
||||||
|
@ -105,5 +112,9 @@ public final class ModelType {
|
||||||
return (PlayerModelKey<E, T>)PLAYER_MODELS.get(race);
|
return (PlayerModelKey<E, T>)PLAYER_MODELS.get(race);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Stream<Map.Entry<Wearable, ModelKey<? extends IGear>>> getWearables() {
|
||||||
|
return GEAR_MODELS.entrySet().stream();
|
||||||
|
}
|
||||||
|
|
||||||
public static void bootstrap() {};
|
public static void bootstrap() {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
import com.minelittlepony.model.IModel;
|
import com.minelittlepony.model.IModel;
|
||||||
import com.minelittlepony.model.gear.IGear;
|
import com.minelittlepony.model.gear.IGear;
|
||||||
|
import com.minelittlepony.pony.meta.Wearable;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ public interface IRenderContext<T extends Entity, M extends IModel> {
|
||||||
|
|
||||||
IRenderContext<?, ?> NULL = (e, g) -> null;
|
IRenderContext<?, ?> NULL = (e, g) -> null;
|
||||||
|
|
||||||
default boolean shouldRender(M model, T entity, IGear gear) {
|
default boolean shouldRender(M model, T entity, Wearable wearable, IGear gear) {
|
||||||
return gear.canRender(model, entity);
|
return gear.canRender(model, entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,5 +22,5 @@ public interface IRenderContext<T extends Entity, M extends IModel> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Identifier getDefaultTexture(T entity, IGear gear);
|
Identifier getDefaultTexture(T entity, Wearable wearable);
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,6 +105,6 @@ public class SaddleBags extends AbstractGear {
|
||||||
if (context.getEntityModel() != null && context.getEntityModel().getMetadata().getRace().isEquivalentTo(Race.CHANGELING)) {
|
if (context.getEntityModel() != null && context.getEntityModel().getMetadata().getRace().isEquivalentTo(Race.CHANGELING)) {
|
||||||
return TEXTURE;
|
return TEXTURE;
|
||||||
}
|
}
|
||||||
return context.getDefaultTexture(entity, this);
|
return context.getDefaultTexture(entity, Wearable.SADDLE_BAGS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,8 @@ import com.minelittlepony.client.model.ModelWrapper;
|
||||||
import com.minelittlepony.client.model.gear.IRenderContext;
|
import com.minelittlepony.client.model.gear.IRenderContext;
|
||||||
import com.minelittlepony.model.BodyPart;
|
import com.minelittlepony.model.BodyPart;
|
||||||
import com.minelittlepony.model.PonyModelConstants;
|
import com.minelittlepony.model.PonyModelConstants;
|
||||||
import com.minelittlepony.model.gear.IGear;
|
|
||||||
import com.minelittlepony.pony.IPony;
|
import com.minelittlepony.pony.IPony;
|
||||||
|
import com.minelittlepony.pony.meta.Wearable;
|
||||||
import com.minelittlepony.util.math.MathUtil;
|
import com.minelittlepony.util.math.MathUtil;
|
||||||
|
|
||||||
import net.minecraft.client.render.entity.model.EntityModel;
|
import net.minecraft.client.render.entity.model.EntityModel;
|
||||||
|
@ -28,7 +28,7 @@ public interface IPonyRender<T extends LivingEntity, M extends EntityModel<T> &
|
||||||
Identifier findTexture(T entity);
|
Identifier findTexture(T entity);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default Identifier getDefaultTexture(T entity, IGear gear) {
|
default Identifier getDefaultTexture(T entity, Wearable wearable) {
|
||||||
return findTexture(entity);
|
return findTexture(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,10 @@ import com.minelittlepony.client.render.entity.feature.LayerPonyArmor;
|
||||||
import com.minelittlepony.client.render.entity.feature.LayerPonyCape;
|
import com.minelittlepony.client.render.entity.feature.LayerPonyCape;
|
||||||
import com.minelittlepony.client.render.entity.feature.LayerPonyCustomHead;
|
import com.minelittlepony.client.render.entity.feature.LayerPonyCustomHead;
|
||||||
import com.minelittlepony.client.render.entity.feature.LayerPonyElytra;
|
import com.minelittlepony.client.render.entity.feature.LayerPonyElytra;
|
||||||
import com.minelittlepony.model.gear.IGear;
|
|
||||||
import com.minelittlepony.mson.api.ModelKey;
|
import com.minelittlepony.mson.api.ModelKey;
|
||||||
import com.minelittlepony.pony.IPony;
|
import com.minelittlepony.pony.IPony;
|
||||||
import com.minelittlepony.pony.meta.Race;
|
import com.minelittlepony.pony.meta.Race;
|
||||||
|
import com.minelittlepony.pony.meta.Wearable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -181,13 +181,13 @@ public class RenderPonyPlayer extends PlayerEntityRenderer implements IPonyRende
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier getDefaultTexture(AbstractClientPlayerEntity entity, IGear gear) {
|
public Identifier getDefaultTexture(AbstractClientPlayerEntity entity, Wearable wearable) {
|
||||||
if (gear == LayerGear.SADDLE_BAGS) {
|
if (wearable == Wearable.SADDLE_BAGS) {
|
||||||
if (getInternalRenderer().getModel().getMetadata().getRace() == Race.BATPONY) {
|
if (getInternalRenderer().getModel().getMetadata().getRace() == Race.BATPONY) {
|
||||||
return SaddleBags.TEXTURE;
|
return SaddleBags.TEXTURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return IPonyRender.super.getDefaultTexture(entity, gear);
|
return IPonyRender.super.getDefaultTexture(entity, wearable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,40 +8,29 @@ import net.minecraft.client.render.entity.model.EntityModel;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.entity.LivingEntity;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.minelittlepony.client.model.IPonyModel;
|
import com.minelittlepony.client.model.IPonyModel;
|
||||||
import com.minelittlepony.client.model.gear.ChristmasHat;
|
import com.minelittlepony.client.model.ModelType;
|
||||||
import com.minelittlepony.client.model.gear.Muffin;
|
|
||||||
import com.minelittlepony.client.model.gear.SaddleBags;
|
|
||||||
import com.minelittlepony.client.model.gear.Stetson;
|
|
||||||
import com.minelittlepony.client.model.gear.WitchHat;
|
|
||||||
import com.minelittlepony.client.render.IPonyRender;
|
import com.minelittlepony.client.render.IPonyRender;
|
||||||
import com.minelittlepony.model.BodyPart;
|
import com.minelittlepony.model.BodyPart;
|
||||||
import com.minelittlepony.model.gear.IGear;
|
import com.minelittlepony.model.gear.IGear;
|
||||||
import com.minelittlepony.model.gear.IStackable;
|
import com.minelittlepony.model.gear.IStackable;
|
||||||
|
import com.minelittlepony.pony.meta.Wearable;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class LayerGear<T extends LivingEntity, M extends EntityModel<T> & IPonyModel<T>> extends AbstractPonyLayer<T, M> {
|
public class LayerGear<T extends LivingEntity, M extends EntityModel<T> & IPonyModel<T>> extends AbstractPonyLayer<T, M> {
|
||||||
|
|
||||||
public static final IGear SADDLE_BAGS = new SaddleBags();
|
private final Map<Wearable, IGear> gears;
|
||||||
public static final IGear WITCH_HAT = new WitchHat();
|
|
||||||
public static final IGear MUFFIN = new Muffin();
|
|
||||||
public static final IGear STETSON = new Stetson();
|
|
||||||
public static final IGear ANTLERS = new ChristmasHat();
|
|
||||||
|
|
||||||
private static List<IGear> gears = Lists.newArrayList(
|
|
||||||
SADDLE_BAGS,
|
|
||||||
WITCH_HAT,
|
|
||||||
MUFFIN,
|
|
||||||
STETSON,
|
|
||||||
ANTLERS
|
|
||||||
);
|
|
||||||
|
|
||||||
public LayerGear(IPonyRender<T, M> renderer) {
|
public LayerGear(IPonyRender<T, M> renderer) {
|
||||||
super(renderer);
|
super(renderer);
|
||||||
|
|
||||||
|
gears = ModelType.getWearables().collect(Collectors.toMap(
|
||||||
|
Map.Entry::getKey,
|
||||||
|
e -> e.getValue().createModel()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,8 +44,11 @@ public class LayerGear<T extends LivingEntity, M extends EntityModel<T> & IPonyM
|
||||||
|
|
||||||
Map<BodyPart, Float> renderStackingOffsets = new HashMap<>();
|
Map<BodyPart, Float> renderStackingOffsets = new HashMap<>();
|
||||||
|
|
||||||
for (IGear gear : gears) {
|
for (Map.Entry<Wearable, IGear> entry : gears.entrySet()) {
|
||||||
if (getContext().shouldRender(model, entity, gear)) {
|
Wearable wearable = entry.getKey();
|
||||||
|
IGear gear = entry.getValue();
|
||||||
|
|
||||||
|
if (getContext().shouldRender(model, entity, wearable, gear)) {
|
||||||
stack.push();
|
stack.push();
|
||||||
model.transform(gear.getGearLocation(), stack);
|
model.transform(gear.getGearLocation(), stack);
|
||||||
model.getBodyPart(gear.getGearLocation()).rotate(stack);
|
model.getBodyPart(gear.getGearLocation()).rotate(stack);
|
||||||
|
|
|
@ -10,10 +10,10 @@ import net.minecraft.village.VillagerProfession;
|
||||||
|
|
||||||
import com.minelittlepony.client.model.ClientPonyModel;
|
import com.minelittlepony.client.model.ClientPonyModel;
|
||||||
import com.minelittlepony.client.render.entity.RenderPonyMob;
|
import com.minelittlepony.client.render.entity.RenderPonyMob;
|
||||||
import com.minelittlepony.client.render.entity.feature.LayerGear;
|
|
||||||
import com.minelittlepony.model.IUnicorn;
|
import com.minelittlepony.model.IUnicorn;
|
||||||
import com.minelittlepony.model.gear.IGear;
|
import com.minelittlepony.model.gear.IGear;
|
||||||
import com.minelittlepony.mson.api.ModelKey;
|
import com.minelittlepony.mson.api.ModelKey;
|
||||||
|
import com.minelittlepony.pony.meta.Wearable;
|
||||||
import com.minelittlepony.util.resources.ITextureSupplier;
|
import com.minelittlepony.util.resources.ITextureSupplier;
|
||||||
|
|
||||||
abstract class AbstractVillagerRenderer<
|
abstract class AbstractVillagerRenderer<
|
||||||
|
@ -33,11 +33,11 @@ abstract class AbstractVillagerRenderer<
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldRender(M model, T entity, IGear gear) {
|
public boolean shouldRender(M model, T entity, Wearable wearable, IGear gear) {
|
||||||
|
|
||||||
boolean special = PonyTextures.isBestPony(entity);
|
boolean special = PonyTextures.isBestPony(entity);
|
||||||
|
|
||||||
if (gear == LayerGear.SADDLE_BAGS) {
|
if (wearable == Wearable.SADDLE_BAGS) {
|
||||||
VillagerProfession profession = entity.getVillagerData().getProfession();
|
VillagerProfession profession = entity.getVillagerData().getProfession();
|
||||||
return !special && profession != VillagerProfession.NONE && (
|
return !special && profession != VillagerProfession.NONE && (
|
||||||
profession == VillagerProfession.CARTOGRAPHER
|
profession == VillagerProfession.CARTOGRAPHER
|
||||||
|
@ -47,19 +47,19 @@ abstract class AbstractVillagerRenderer<
|
||||||
|| profession == VillagerProfession.SHEPHERD);
|
|| profession == VillagerProfession.SHEPHERD);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gear == LayerGear.MUFFIN) {
|
if (wearable == Wearable.MUFFIN) {
|
||||||
return PonyTextures.isCrownPony(entity);
|
return PonyTextures.isCrownPony(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.shouldRender(model, entity, gear);
|
return super.shouldRender(model, entity, wearable, gear);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier getDefaultTexture(T villager, IGear gear) {
|
public Identifier getDefaultTexture(T villager, Wearable wearable) {
|
||||||
if (gear == LayerGear.SADDLE_BAGS) {
|
if (wearable == Wearable.SADDLE_BAGS) {
|
||||||
return ClothingLayer.getClothingTexture(villager, entityType);
|
return ClothingLayer.getClothingTexture(villager, entityType);
|
||||||
}
|
}
|
||||||
return super.getDefaultTexture(villager, gear);
|
return super.getDefaultTexture(villager, wearable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -7,8 +7,9 @@ import com.minelittlepony.client.model.gear.IRenderContext;
|
||||||
import com.minelittlepony.model.BodyPart;
|
import com.minelittlepony.model.BodyPart;
|
||||||
import com.minelittlepony.model.IModel;
|
import com.minelittlepony.model.IModel;
|
||||||
import com.minelittlepony.model.IPart;
|
import com.minelittlepony.model.IPart;
|
||||||
|
import com.minelittlepony.mson.api.MsonModel;
|
||||||
|
|
||||||
public interface IGear extends IPart {
|
public interface IGear extends IPart, MsonModel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if this wearable can and is worn by the selected entity.
|
* Determines if this wearable can and is worn by the selected entity.
|
||||||
|
|
Loading…
Reference in a new issue