mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2025-02-13 08:14: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.render.entity.RenderPonyPlayer;
|
||||
import com.minelittlepony.client.render.entity.RenderSeaponyPlayer;
|
||||
import com.minelittlepony.model.gear.IGear;
|
||||
import com.minelittlepony.mson.api.ModelKey;
|
||||
import com.minelittlepony.mson.api.Mson;
|
||||
import com.minelittlepony.mson.api.MsonModel;
|
||||
import com.minelittlepony.pony.meta.Race;
|
||||
import com.minelittlepony.pony.meta.Wearable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -40,10 +42,12 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class ModelType {
|
||||
|
||||
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<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_OUTER = register("armour_outer", ModelPonyArmour::new);
|
||||
|
||||
public static final ModelKey<Stetson> STETSON = registerGear("stetson", Stetson::new);
|
||||
public static final ModelKey<SaddleBags> SADDLEBAGS = registerGear("saddlebags", SaddleBags::new);
|
||||
public static final ModelKey<Muffin> MUFFIN = registerGear("muffin", Muffin::new);
|
||||
public static final ModelKey<WitchHat> WITCH_HAT = registerGear("witch_hat", WitchHat::new);
|
||||
public static final ModelKey<ChristmasHat> ANTLERS = registerGear("antlers", ChristmasHat::new);
|
||||
public static final ModelKey<Stetson> STETSON = registerGear("stetson", Wearable.STETSON, Stetson::new);
|
||||
public static final ModelKey<SaddleBags> SADDLEBAGS = registerGear("saddlebags", Wearable.SADDLE_BAGS, SaddleBags::new);
|
||||
public static final ModelKey<Muffin> MUFFIN = registerGear("muffin", Wearable.MUFFIN, Muffin::new);
|
||||
public static final ModelKey<WitchHat> WITCH_HAT = registerGear("witch_hat", Wearable.HAT, WitchHat::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<?, 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) {
|
||||
return register("gear/" + name, constructor);
|
||||
@SuppressWarnings("unchecked")
|
||||
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) {
|
||||
|
@ -105,5 +112,9 @@ public final class ModelType {
|
|||
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() {};
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import net.minecraft.util.Identifier;
|
|||
|
||||
import com.minelittlepony.model.IModel;
|
||||
import com.minelittlepony.model.gear.IGear;
|
||||
import com.minelittlepony.pony.meta.Wearable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
@ -12,7 +13,7 @@ public interface IRenderContext<T extends Entity, M extends IModel> {
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -21,5 +22,5 @@ public interface IRenderContext<T extends Entity, M extends IModel> {
|
|||
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)) {
|
||||
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.model.BodyPart;
|
||||
import com.minelittlepony.model.PonyModelConstants;
|
||||
import com.minelittlepony.model.gear.IGear;
|
||||
import com.minelittlepony.pony.IPony;
|
||||
import com.minelittlepony.pony.meta.Wearable;
|
||||
import com.minelittlepony.util.math.MathUtil;
|
||||
|
||||
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);
|
||||
|
||||
@Override
|
||||
default Identifier getDefaultTexture(T entity, IGear gear) {
|
||||
default Identifier getDefaultTexture(T entity, Wearable wearable) {
|
||||
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.LayerPonyCustomHead;
|
||||
import com.minelittlepony.client.render.entity.feature.LayerPonyElytra;
|
||||
import com.minelittlepony.model.gear.IGear;
|
||||
import com.minelittlepony.mson.api.ModelKey;
|
||||
import com.minelittlepony.pony.IPony;
|
||||
import com.minelittlepony.pony.meta.Race;
|
||||
import com.minelittlepony.pony.meta.Wearable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -181,13 +181,13 @@ public class RenderPonyPlayer extends PlayerEntityRenderer implements IPonyRende
|
|||
}
|
||||
|
||||
@Override
|
||||
public Identifier getDefaultTexture(AbstractClientPlayerEntity entity, IGear gear) {
|
||||
if (gear == LayerGear.SADDLE_BAGS) {
|
||||
public Identifier getDefaultTexture(AbstractClientPlayerEntity entity, Wearable wearable) {
|
||||
if (wearable == Wearable.SADDLE_BAGS) {
|
||||
if (getInternalRenderer().getModel().getMetadata().getRace() == Race.BATPONY) {
|
||||
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.entity.LivingEntity;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.minelittlepony.client.model.IPonyModel;
|
||||
import com.minelittlepony.client.model.gear.ChristmasHat;
|
||||
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.model.ModelType;
|
||||
import com.minelittlepony.client.render.IPonyRender;
|
||||
import com.minelittlepony.model.BodyPart;
|
||||
import com.minelittlepony.model.gear.IGear;
|
||||
import com.minelittlepony.model.gear.IStackable;
|
||||
import com.minelittlepony.pony.meta.Wearable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
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 static final IGear SADDLE_BAGS = new SaddleBags();
|
||||
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
|
||||
);
|
||||
private final Map<Wearable, IGear> gears;
|
||||
|
||||
public LayerGear(IPonyRender<T, M> renderer) {
|
||||
super(renderer);
|
||||
|
||||
gears = ModelType.getWearables().collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
e -> e.getValue().createModel()
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -55,8 +44,11 @@ public class LayerGear<T extends LivingEntity, M extends EntityModel<T> & IPonyM
|
|||
|
||||
Map<BodyPart, Float> renderStackingOffsets = new HashMap<>();
|
||||
|
||||
for (IGear gear : gears) {
|
||||
if (getContext().shouldRender(model, entity, gear)) {
|
||||
for (Map.Entry<Wearable, IGear> entry : gears.entrySet()) {
|
||||
Wearable wearable = entry.getKey();
|
||||
IGear gear = entry.getValue();
|
||||
|
||||
if (getContext().shouldRender(model, entity, wearable, gear)) {
|
||||
stack.push();
|
||||
model.transform(gear.getGearLocation(), 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.render.entity.RenderPonyMob;
|
||||
import com.minelittlepony.client.render.entity.feature.LayerGear;
|
||||
import com.minelittlepony.model.IUnicorn;
|
||||
import com.minelittlepony.model.gear.IGear;
|
||||
import com.minelittlepony.mson.api.ModelKey;
|
||||
import com.minelittlepony.pony.meta.Wearable;
|
||||
import com.minelittlepony.util.resources.ITextureSupplier;
|
||||
|
||||
abstract class AbstractVillagerRenderer<
|
||||
|
@ -33,11 +33,11 @@ abstract class AbstractVillagerRenderer<
|
|||
}
|
||||
|
||||
@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);
|
||||
|
||||
if (gear == LayerGear.SADDLE_BAGS) {
|
||||
if (wearable == Wearable.SADDLE_BAGS) {
|
||||
VillagerProfession profession = entity.getVillagerData().getProfession();
|
||||
return !special && profession != VillagerProfession.NONE && (
|
||||
profession == VillagerProfession.CARTOGRAPHER
|
||||
|
@ -47,19 +47,19 @@ abstract class AbstractVillagerRenderer<
|
|||
|| profession == VillagerProfession.SHEPHERD);
|
||||
}
|
||||
|
||||
if (gear == LayerGear.MUFFIN) {
|
||||
if (wearable == Wearable.MUFFIN) {
|
||||
return PonyTextures.isCrownPony(entity);
|
||||
}
|
||||
|
||||
return super.shouldRender(model, entity, gear);
|
||||
return super.shouldRender(model, entity, wearable, gear);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getDefaultTexture(T villager, IGear gear) {
|
||||
if (gear == LayerGear.SADDLE_BAGS) {
|
||||
public Identifier getDefaultTexture(T villager, Wearable wearable) {
|
||||
if (wearable == Wearable.SADDLE_BAGS) {
|
||||
return ClothingLayer.getClothingTexture(villager, entityType);
|
||||
}
|
||||
return super.getDefaultTexture(villager, gear);
|
||||
return super.getDefaultTexture(villager, wearable);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,8 +7,9 @@ import com.minelittlepony.client.model.gear.IRenderContext;
|
|||
import com.minelittlepony.model.BodyPart;
|
||||
import com.minelittlepony.model.IModel;
|
||||
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.
|
||||
|
|
Loading…
Reference in a new issue