From d73736edce0a3f8125df68f496cf60a342e3599d Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 28 May 2019 01:50:45 +0200 Subject: [PATCH] Refactoring phase 1 --- .../com/minelittlepony/client/Config.java | 56 ---------- .../com/minelittlepony/client/FabMod.java | 8 +- .../minelittlepony/client/IModUtilities.java | 2 - .../client/model/AbstractPonyModel.java | 1 + .../client/model/entities/ModelSeapony.java | 8 +- .../client/model/races/PlayerModels.java | 100 ++++++++++-------- .../client/render/LevitatingItemRenderer.java | 4 +- .../client/render/RenderPony.java | 47 ++++---- .../render/entities/RenderEnderStallion.java | 6 +- .../render/entities/RenderPonyGuardian.java | 5 +- .../render/entities/RenderPonyIllager.java | 4 +- .../render/{ => entities}/RenderPonyMob.java | 25 +++-- .../render/entities/RenderPonySkeleton.java | 4 +- .../render/entities/RenderPonyVillager.java | 4 +- .../render/entities/RenderPonyWitch.java | 4 +- .../render/entities/RenderPonyZombie.java | 6 +- .../entities/RenderPonyZombieVillager.java | 4 +- .../entities/player/RenderPonyPlayer.java | 14 +-- .../entities/player/RenderSeaponyPlayer.java | 12 +-- .../client/settings/ClientPonyConfig.java | 2 +- .../client/transform/PonyPosture.java | 16 ++- .../client/transform/PostureElytra.java | 4 +- .../client/transform/PostureFalling.java | 4 +- .../client/transform/PostureFlight.java | 4 +- .../client/transform/PostureStanding.java | 16 +++ .../com/minelittlepony/model/IPonyModel.java | 6 +- .../minelittlepony/settings/PonyConfig.java | 3 +- .../settings/SensibleJsonConfig.java | 64 +++++++++++ 28 files changed, 226 insertions(+), 207 deletions(-) delete mode 100644 src/client/java/com/minelittlepony/client/Config.java rename src/client/java/com/minelittlepony/client/render/{ => entities}/RenderPonyMob.java (91%) create mode 100644 src/client/java/com/minelittlepony/client/transform/PostureStanding.java create mode 100644 src/main/java/com/minelittlepony/settings/SensibleJsonConfig.java diff --git a/src/client/java/com/minelittlepony/client/Config.java b/src/client/java/com/minelittlepony/client/Config.java deleted file mode 100644 index a23ccd2b..00000000 --- a/src/client/java/com/minelittlepony/client/Config.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.minelittlepony.client; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.stream.JsonWriter; -import com.minelittlepony.client.settings.ClientPonyConfig; - -import java.io.BufferedReader; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -class Config extends ClientPonyConfig { - static final Gson gson = new GsonBuilder() - .setPrettyPrinting() - .excludeFieldsWithoutExposeAnnotation() - .create(); - - private final Path configFile; - - Config(Path file) { - configFile = file; - } - - @Override - public void save() { - - try (JsonWriter writer = new JsonWriter(Files.newBufferedWriter(configFile))) { - writer.setIndent(" "); - - gson.toJson(this, Config.class, writer); - } catch (IOException e) { - e.printStackTrace(); - } - } - - static Config of(Path file) { - Config result = null; - - if (Files.exists(file)) { - try (BufferedReader s = Files.newBufferedReader(file)) { - result = gson.fromJson(s, Config.class); - } catch (IOException ignored) { - result = null; - } - } - - if (result == null) { - result = new Config(file); - } - - result.save(); - - return result; - } -} \ No newline at end of file diff --git a/src/client/java/com/minelittlepony/client/FabMod.java b/src/client/java/com/minelittlepony/client/FabMod.java index ba482ed4..c518ffb6 100644 --- a/src/client/java/com/minelittlepony/client/FabMod.java +++ b/src/client/java/com/minelittlepony/client/FabMod.java @@ -9,7 +9,9 @@ import net.minecraft.client.render.entity.EntityRenderDispatcher; import net.minecraft.client.render.entity.EntityRenderer; import net.minecraft.entity.Entity; +import com.minelittlepony.client.settings.ClientPonyConfig; import com.minelittlepony.hdskins.mixin.MixinEntityRenderDispatcher; +import com.minelittlepony.settings.SensibleJsonConfig; import java.nio.file.Path; import java.util.function.Function; @@ -20,7 +22,7 @@ public class FabMod implements ClientModInitializer, IModUtilities { @Override public void onInitializeClient() { - mlp.init(Config.of(getConfigDirectory())); + mlp.init(SensibleJsonConfig.of(getConfigDirectory(), ClientPonyConfig::new)); mlp.postInit(MinecraftClient.getInstance()); } @@ -34,10 +36,6 @@ public class FabMod implements ClientModInitializer, IModUtilities { ((MixinEntityRenderDispatcher)mx).getRenderers().put(type, renderer.apply(mx)); } - public float getRenderPartialTicks() { - return MinecraftClient.getInstance().getTickDelta(); - } - @Override public Path getConfigDirectory() { return FabricLoader.getInstance().getConfigDirectory().toPath(); diff --git a/src/client/java/com/minelittlepony/client/IModUtilities.java b/src/client/java/com/minelittlepony/client/IModUtilities.java index e2c1239a..a209dab8 100644 --- a/src/client/java/com/minelittlepony/client/IModUtilities.java +++ b/src/client/java/com/minelittlepony/client/IModUtilities.java @@ -18,8 +18,6 @@ public interface IModUtilities { return false; } - float getRenderPartialTicks(); - Path getConfigDirectory(); Path getAssetsDirectory(); diff --git a/src/client/java/com/minelittlepony/client/model/AbstractPonyModel.java b/src/client/java/com/minelittlepony/client/model/AbstractPonyModel.java index f754f8db..757ec154 100644 --- a/src/client/java/com/minelittlepony/client/model/AbstractPonyModel.java +++ b/src/client/java/com/minelittlepony/client/model/AbstractPonyModel.java @@ -89,6 +89,7 @@ public abstract class AbstractPonyModel extends ClientPo motionLerp = MathUtil.clampLimit(zMotion * 30, 1); } + @Override public void updateLivingState(T entity, IPony pony) { isChild = entity.isBaby(); isSneaking = entity.isSneaking(); diff --git a/src/client/java/com/minelittlepony/client/model/entities/ModelSeapony.java b/src/client/java/com/minelittlepony/client/model/entities/ModelSeapony.java index eddc8279..41fd1794 100644 --- a/src/client/java/com/minelittlepony/client/model/entities/ModelSeapony.java +++ b/src/client/java/com/minelittlepony/client/model/entities/ModelSeapony.java @@ -24,11 +24,15 @@ public class ModelSeapony extends ModelUnicorn { PlaneRenderer centerFin; PlaneRenderer rightFin; - public ModelSeapony() { - super(false); + public ModelSeapony(boolean smallArms) { + super(smallArms); textureHeight = 64; } + public ModelSeapony() { + this(false); + } + @Override public IEquestrianArmour createArmour() { return new PonyArmor<>(new Armour(), new Armour()); diff --git a/src/client/java/com/minelittlepony/client/model/races/PlayerModels.java b/src/client/java/com/minelittlepony/client/model/races/PlayerModels.java index 11515a09..93334909 100644 --- a/src/client/java/com/minelittlepony/client/model/races/PlayerModels.java +++ b/src/client/java/com/minelittlepony/client/model/races/PlayerModels.java @@ -1,8 +1,6 @@ package com.minelittlepony.client.model.races; import com.google.common.collect.Maps; -import com.minelittlepony.client.model.AbstractPonyModel; -import com.minelittlepony.client.model.ModelWrapper; import com.minelittlepony.client.model.entities.ModelSeapony; import com.minelittlepony.client.render.entities.player.RenderPonyPlayer; import com.minelittlepony.client.render.entities.player.RenderSeaponyPlayer; @@ -10,31 +8,34 @@ import com.minelittlepony.hdskins.VanillaModels; import com.minelittlepony.model.IModel; import com.minelittlepony.pony.meta.Race; +import javax.annotation.Nullable; + import net.minecraft.client.render.entity.EntityRenderDispatcher; import net.minecraft.entity.LivingEntity; import java.util.Map; +import java.util.function.Function; public enum PlayerModels { /** * The default non-pony model. This is typically handled my the vanilla renderer. */ - HUMAN(VanillaModels.DEFAULT, Race.HUMAN, ModelEarthPony::new), - EARTH("earthpony", Race.EARTH, ModelEarthPony::new), - PEGASUS("pegasus", Race.PEGASUS, ModelPegasus::new), - BATPONY("batpony", Race.BATPONY, ModelBatpony::new), - UNICORN("unicorn", Race.UNICORN, ModelUnicorn::new), - ALICORN("alicorn", Race.ALICORN, ModelAlicorn::new), - CHANGELING("changeling", Race.CHANGELING, ModelChangeling::new), - ZEBRA("zebra", Race.ZEBRA, ModelZebra::new), - SEAPONY("seapony", Race.SEAPONY, a -> new ModelSeapony<>()) { + DEFAULT(VanillaModels.DEFAULT, VanillaModels.SLIM, Race.HUMAN, ModelEarthPony::new), + EARTHPONY(Race.EARTH, ModelEarthPony::new), + PEGASUS(Race.PEGASUS, ModelPegasus::new), + BATPONY(Race.BATPONY, ModelBatpony::new), + UNICORN(Race.UNICORN, ModelUnicorn::new), + ALICORN(Race.ALICORN, ModelAlicorn::new), + CHANGELING(Race.CHANGELING, ModelChangeling::new), + ZEBRA(Race.ZEBRA, ModelZebra::new), + SEAPONY(Race.SEAPONY, ModelSeapony::new) { @Override public RenderPonyPlayer createRenderer(EntityRenderDispatcher manager, boolean slimArms) { return new RenderSeaponyPlayer(manager, slimArms, PlayerModels.UNICORN.getModel(slimArms), getModel(slimArms)); } }; - private static Map raceModelsMap = Maps.newEnumMap(Race.class); + private static final Map raceModelsMap = Maps.newEnumMap(Race.class); static { for (PlayerModels i : values()) { @@ -42,48 +43,41 @@ public enum PlayerModels { } } - private final ModelResolver resolver; + private final Function resolver; - private ModelWrapper normal; - private ModelWrapper slim; - - private final String normalKey, slimKey; + private final PendingModel normal; + private final PendingModel slim; private final Race race; - PlayerModels(String key, Race race, ModelResolver resolver) { - this(key, VanillaModels.SLIM + key, race, resolver); - } - - PlayerModels(String normalKey, String slimKey, Race race, ModelResolver resolver) { - this.normalKey = normalKey; - this.slimKey = slimKey; + PlayerModels(Race race, Function resolver) { + normal = new PendingModel(name().toLowerCase()); + slim = new PendingModel(VanillaModels.SLIM + normal.key); this.resolver = resolver; this.race = race; } - @SuppressWarnings("unchecked") - public ModelWrapper getModel(boolean isSlim) { + PlayerModels(String normalKey, String slimKey, Race race, Function resolver) { + normal = new PendingModel(normalKey); + slim = new PendingModel(slimKey); - if (isSlim) { - if (slim == null) { - slim = new ModelWrapper<>(resolver.resolve(isSlim)); - } + this.resolver = resolver; - return (ModelWrapper)slim; - } - - if (normal == null) { - normal = new ModelWrapper<>(resolver.resolve(isSlim)); - } - - return (ModelWrapper)normal; + this.race = race; } - public String getId(boolean useSlimArms) { - return useSlimArms ? slimKey : normalKey; + public PendingModel getPendingModel(boolean isSlim) { + return isSlim ? slim : normal; + } + + public M getModel(boolean isSlim) { + return getPendingModel(isSlim).getModel(isSlim); + } + + public String getId(boolean isSlim) { + return getPendingModel(isSlim).key; } public RenderPonyPlayer createRenderer(EntityRenderDispatcher manager, boolean slimArms) { @@ -91,14 +85,26 @@ public enum PlayerModels { } public static PlayerModels forRace(Race race) { - return raceModelsMap.getOrDefault(race.getAlias(), HUMAN); + return raceModelsMap.getOrDefault(race.getAlias(), DEFAULT); } - /** - * FIXME: PMAPI fields are null when the game starts. - */ - @FunctionalInterface - static interface ModelResolver { - AbstractPonyModel resolve(boolean slim); + private final class PendingModel { + @Nullable + private IModel model; + + private final String key; + + PendingModel(String key) { + this.key = key; + } + + @SuppressWarnings("unchecked") + public M getModel(boolean isSlim) { + if (model == null) { + model = resolver.apply(isSlim); + } + + return (M)model; + } } } diff --git a/src/client/java/com/minelittlepony/client/render/LevitatingItemRenderer.java b/src/client/java/com/minelittlepony/client/render/LevitatingItemRenderer.java index a508ef47..2eaac4c1 100644 --- a/src/client/java/com/minelittlepony/client/render/LevitatingItemRenderer.java +++ b/src/client/java/com/minelittlepony/client/render/LevitatingItemRenderer.java @@ -3,7 +3,6 @@ package com.minelittlepony.client.render; import org.lwjgl.opengl.GL14; import com.minelittlepony.MineLittlePony; -import com.minelittlepony.client.MineLPClient; import com.minelittlepony.client.ducks.IRenderItem; import com.minelittlepony.client.render.tileentities.skull.PonySkullRenderer; import com.minelittlepony.client.util.render.Color; @@ -20,7 +19,6 @@ import net.minecraft.util.UseAction; import static com.mojang.blaze3d.platform.GlStateManager.*; -@SuppressWarnings("deprecation") // ItemCameraTransforms is deprecated by forge but we still need it. public class LevitatingItemRenderer { public static void enableItemGlowRenderProfile() { @@ -118,7 +116,7 @@ public class LevitatingItemRenderer { boolean doNormal = entity.getItemUseTime() <= 0 || action == UseAction.NONE; if (doNormal) { // eating, blocking, and drinking are not transformed. Only held items. - float ticks = MineLPClient.getInstance().getModUtilities().getRenderPartialTicks() - entity.age; + float ticks = MinecraftClient.getInstance().getTickDelta() - entity.age; float floatAmount = (float)Math.sin(ticks / 9) / 40; float driftAmount = (float)Math.cos(ticks / 6) / 40; diff --git a/src/client/java/com/minelittlepony/client/render/RenderPony.java b/src/client/java/com/minelittlepony/client/render/RenderPony.java index 720dfc62..ff16f4d7 100644 --- a/src/client/java/com/minelittlepony/client/render/RenderPony.java +++ b/src/client/java/com/minelittlepony/client/render/RenderPony.java @@ -2,7 +2,6 @@ package com.minelittlepony.client.render; import com.minelittlepony.MineLittlePony; import com.minelittlepony.client.PonyRenderManager; -import com.minelittlepony.client.model.AbstractPonyModel; import com.minelittlepony.client.model.ModelWrapper; import com.minelittlepony.client.transform.PonyPosture; import com.minelittlepony.model.IPonyModel; @@ -10,7 +9,7 @@ import com.minelittlepony.pony.IPony; import com.minelittlepony.util.math.MathUtil; import com.mojang.blaze3d.platform.GlStateManager; -import javax.annotation.Nullable; +import javax.annotation.Nonnull; import net.minecraft.client.render.VisibleRegion; import net.minecraft.client.render.entity.model.EntityModel; @@ -21,13 +20,13 @@ public class RenderPony & IPony public ModelWrapper playerModel; - protected AbstractPonyModel ponyModel; + private M ponyModel; private IPony pony; - private IPonyRender renderer; + private final IPonyRender renderer; - private FrustrumCheck frustrum = new FrustrumCheck<>(this); + private final FrustrumCheck frustrum = new FrustrumCheck<>(this); public static void enableModelRenderProfile() { GlStateManager.enableBlend(); @@ -95,54 +94,44 @@ public class RenderPony & IPony @SuppressWarnings("unchecked") public void applyPostureTransform(T player, float yaw, float ticks) { - PonyPosture posture = getPosture(player); - if (posture != null && posture.applies(player)) { - double motionX = player.x - player.prevX; - double motionY = player.onGround ? 0 : player.y - player.prevY; - double motionZ = player.x - player.prevZ; - ((PonyPosture)posture).transform(ponyModel, player, motionX, motionY, motionZ, yaw, ticks); - } + ((PonyPosture)getPosture(player)).apply(player, ponyModel, yaw, ticks, 1); } @SuppressWarnings("unchecked") public void applyPostureRiding(T player, float yaw, float ticks) { - PonyPosture posture = getPosture(player); - if (posture != null && posture.applies(player)) { - double motionX = player.x - player.prevX; - double motionY = player.onGround ? 0 : player.y - player.prevY; - double motionZ = player.z - player.prevZ; - - ((PonyPosture)posture).transform(ponyModel, player, motionX, -motionY, motionZ, yaw, ticks); - } + ((PonyPosture)getPosture(player)).apply(player, ponyModel, yaw, ticks, -1); } - @Nullable + @Nonnull private PonyPosture getPosture(T entity) { if (entity.isFallFlying()) { return PonyPosture.ELYTRA; } if (entity.isAlive() && entity.isSleeping()) { - return null; + return PonyPosture.DEFAULT; } - if (ponyModel.isSwimming()) { + if (getModel().isSwimming()) { return PonyPosture.SWIMMING; } - if (ponyModel.isGoingFast()) { + if (getModel().isGoingFast()) { return PonyPosture.FLIGHT; } return PonyPosture.FALLING; } - @SuppressWarnings("unchecked") + public M getModel() { + return playerModel.getBody(); + } + public M setPonyModel(ModelWrapper model) { playerModel = model; - ponyModel = (AbstractPonyModel)playerModel.getBody(); + ponyModel = playerModel.getBody(); - return (M)ponyModel; + return ponyModel; } public void updateModel(T entity) { @@ -156,11 +145,11 @@ public class RenderPony & IPony } public float getShadowScale() { - return ponyModel.getSize().getShadowSize(); + return getModel().getSize().getShadowSize(); } public float getScaleFactor() { - return ponyModel.getSize().getScaleFactor(); + return getModel().getSize().getScaleFactor(); } public double getNamePlateYOffset(T entity, double initial) { diff --git a/src/client/java/com/minelittlepony/client/render/entities/RenderEnderStallion.java b/src/client/java/com/minelittlepony/client/render/entities/RenderEnderStallion.java index 73618a25..4f9a6375 100644 --- a/src/client/java/com/minelittlepony/client/render/entities/RenderEnderStallion.java +++ b/src/client/java/com/minelittlepony/client/render/entities/RenderEnderStallion.java @@ -1,8 +1,6 @@ package com.minelittlepony.client.render.entities; -import com.minelittlepony.client.model.ModelWrapper; import com.minelittlepony.client.model.entities.ModelEnderStallion; -import com.minelittlepony.client.render.RenderPonyMob; import com.minelittlepony.client.render.layer.LayerEyeGlow; import com.minelittlepony.client.render.layer.LayerHeldPonyItem; import com.minelittlepony.client.render.layer.LayerHeldPonyItemMagical; @@ -24,10 +22,8 @@ public class RenderEnderStallion extends RenderPonyMob MODEL_WRAPPER = new ModelWrapper<>(new ModelEnderStallion()); - public RenderEnderStallion(EntityRenderDispatcher manager) { - super(manager, MODEL_WRAPPER); + super(manager, new ModelEnderStallion()); } @Override diff --git a/src/client/java/com/minelittlepony/client/render/entities/RenderPonyGuardian.java b/src/client/java/com/minelittlepony/client/render/entities/RenderPonyGuardian.java index 2e499d5d..d0da966c 100644 --- a/src/client/java/com/minelittlepony/client/render/entities/RenderPonyGuardian.java +++ b/src/client/java/com/minelittlepony/client/render/entities/RenderPonyGuardian.java @@ -3,9 +3,8 @@ package com.minelittlepony.client.render.entities; import javax.annotation.Nonnull; import com.minelittlepony.client.mixin.IResizeable; -import com.minelittlepony.client.model.ModelWrapper; import com.minelittlepony.client.model.entities.ModelGuardianPony; -import com.minelittlepony.client.render.RenderPonyMob.Proxy; +import com.minelittlepony.client.render.entities.RenderPonyMob.Proxy; import com.minelittlepony.client.render.layer.LayerHeldPonyItem; import com.minelittlepony.client.render.layer.LayerHeldPonyItemMagical; import com.mojang.blaze3d.platform.GlStateManager; @@ -27,7 +26,7 @@ public class RenderPonyGuardian extends GuardianEntityRenderer { super(manager); features.clear(); - ponyRenderer = new Proxy(features, manager, new ModelWrapper<>(new ModelGuardianPony())) { + ponyRenderer = new Proxy(features, manager, new ModelGuardianPony()) { @Override public Identifier findTexture(GuardianEntity entity) { return SEAPONY; diff --git a/src/client/java/com/minelittlepony/client/render/entities/RenderPonyIllager.java b/src/client/java/com/minelittlepony/client/render/entities/RenderPonyIllager.java index c8e8f2c9..9aa6c892 100644 --- a/src/client/java/com/minelittlepony/client/render/entities/RenderPonyIllager.java +++ b/src/client/java/com/minelittlepony/client/render/entities/RenderPonyIllager.java @@ -1,8 +1,6 @@ package com.minelittlepony.client.render.entities; -import com.minelittlepony.client.model.ModelWrapper; import com.minelittlepony.client.model.entities.ModelIllagerPony; -import com.minelittlepony.client.render.RenderPonyMob; import com.minelittlepony.client.render.layer.LayerHeldItemIllager; import com.minelittlepony.client.render.layer.LayerHeldPonyItem; import com.mojang.blaze3d.platform.GlStateManager; @@ -23,7 +21,7 @@ public abstract class RenderPonyIllager extends RenderP public static final Identifier VINDICATOR = new Identifier("minelittlepony", "textures/entity/illager/vindicator_pony.png"); public RenderPonyIllager(EntityRenderDispatcher manager) { - super(manager, new ModelWrapper<>(new ModelIllagerPony<>())); + super(manager, new ModelIllagerPony<>()); } @Override diff --git a/src/client/java/com/minelittlepony/client/render/RenderPonyMob.java b/src/client/java/com/minelittlepony/client/render/entities/RenderPonyMob.java similarity index 91% rename from src/client/java/com/minelittlepony/client/render/RenderPonyMob.java rename to src/client/java/com/minelittlepony/client/render/entities/RenderPonyMob.java index 971360c6..818dd587 100644 --- a/src/client/java/com/minelittlepony/client/render/RenderPonyMob.java +++ b/src/client/java/com/minelittlepony/client/render/entities/RenderPonyMob.java @@ -1,8 +1,11 @@ -package com.minelittlepony.client.render; +package com.minelittlepony.client.render.entities; import com.minelittlepony.MineLittlePony; import com.minelittlepony.client.model.ClientPonyModel; import com.minelittlepony.client.model.ModelWrapper; +import com.minelittlepony.client.render.DebugBoundingBoxRenderer; +import com.minelittlepony.client.render.IPonyRender; +import com.minelittlepony.client.render.RenderPony; import com.minelittlepony.client.render.layer.LayerGear; import com.minelittlepony.client.render.layer.LayerHeldPonyItem; import com.minelittlepony.client.render.layer.LayerHeldPonyItemMagical; @@ -31,10 +34,10 @@ public abstract class RenderPonyMob renderPony = new RenderPony(this); - public RenderPonyMob(EntityRenderDispatcher manager, ModelWrapper model) { - super(manager, model.getBody(), 0.5F); + public RenderPonyMob(EntityRenderDispatcher manager, M model) { + super(manager, model, 0.5F); - renderPony.setPonyModel(model); + this.model = renderPony.setPonyModel(new ModelWrapper<>(model)); addLayers(); } @@ -94,11 +97,6 @@ public abstract class RenderPonyMob & IUnicorn> extends RenderPonyMob { - public Caster(EntityRenderDispatcher manager, ModelWrapper model) { + public Caster(EntityRenderDispatcher manager, M model) { super(manager, model); } @@ -131,7 +134,7 @@ public abstract class RenderPonyMob & IPonyModel> extends RenderPonyMob { @SuppressWarnings({"rawtypes", "unchecked"}) - public Proxy(List exportedLayers, EntityRenderDispatcher manager, ModelWrapper model) { + public Proxy(List exportedLayers, EntityRenderDispatcher manager, M model) { super(manager, model); exportedLayers.addAll(features); diff --git a/src/client/java/com/minelittlepony/client/render/entities/RenderPonySkeleton.java b/src/client/java/com/minelittlepony/client/render/entities/RenderPonySkeleton.java index d9af0deb..e6c7497c 100644 --- a/src/client/java/com/minelittlepony/client/render/entities/RenderPonySkeleton.java +++ b/src/client/java/com/minelittlepony/client/render/entities/RenderPonySkeleton.java @@ -1,8 +1,6 @@ package com.minelittlepony.client.render.entities; -import com.minelittlepony.client.model.ModelWrapper; import com.minelittlepony.client.model.entities.ModelSkeletonPony; -import com.minelittlepony.client.render.RenderPonyMob; import com.minelittlepony.client.render.layer.LayerHeldPonyItem; import com.minelittlepony.client.render.layer.LayerHeldPonyItemMagical; import com.minelittlepony.client.render.layer.LayerPonyStrayOverlay; @@ -21,7 +19,7 @@ public class RenderPonySkeleton extends public static final Identifier STRAY = new Identifier("minelittlepony", "textures/entity/skeleton/stray_pony.png"); public RenderPonySkeleton(EntityRenderDispatcher manager) { - super(manager, new ModelWrapper<>(new ModelSkeletonPony<>())); + super(manager, new ModelSkeletonPony<>()); } @Override diff --git a/src/client/java/com/minelittlepony/client/render/entities/RenderPonyVillager.java b/src/client/java/com/minelittlepony/client/render/entities/RenderPonyVillager.java index 565ef682..3bf48fdc 100644 --- a/src/client/java/com/minelittlepony/client/render/entities/RenderPonyVillager.java +++ b/src/client/java/com/minelittlepony/client/render/entities/RenderPonyVillager.java @@ -1,8 +1,6 @@ package com.minelittlepony.client.render.entities; -import com.minelittlepony.client.model.ModelWrapper; import com.minelittlepony.client.model.entities.ModelVillagerPony; -import com.minelittlepony.client.render.RenderPonyMob; import com.minelittlepony.util.resources.FormattedTextureSupplier; import com.minelittlepony.util.resources.ITextureSupplier; import com.mojang.blaze3d.platform.GlStateManager; @@ -23,7 +21,7 @@ public class RenderPonyVillager extends RenderPonyMob.Caster PROFESSIONS = new VillagerProfessionTextureCache(FORMATTER, DEFAULT); public RenderPonyVillager(EntityRenderDispatcher manager) { - super(manager, new ModelWrapper<>(new ModelVillagerPony<>())); + super(manager, new ModelVillagerPony<>()); } @Override diff --git a/src/client/java/com/minelittlepony/client/render/entities/RenderPonyWitch.java b/src/client/java/com/minelittlepony/client/render/entities/RenderPonyWitch.java index 9ea27b22..21f6e9e9 100644 --- a/src/client/java/com/minelittlepony/client/render/entities/RenderPonyWitch.java +++ b/src/client/java/com/minelittlepony/client/render/entities/RenderPonyWitch.java @@ -1,8 +1,6 @@ package com.minelittlepony.client.render.entities; -import com.minelittlepony.client.model.ModelWrapper; import com.minelittlepony.client.model.entities.ModelWitchPony; -import com.minelittlepony.client.render.RenderPonyMob; import com.minelittlepony.client.render.layer.LayerHeldPonyItem; import com.mojang.blaze3d.platform.GlStateManager; @@ -18,7 +16,7 @@ public class RenderPonyWitch extends RenderPonyMob private static final Identifier WITCH_TEXTURES = new Identifier("minelittlepony", "textures/entity/witch_pony.png"); public RenderPonyWitch(EntityRenderDispatcher manager) { - super(manager, new ModelWrapper<>(new ModelWitchPony())); + super(manager, new ModelWitchPony()); } @Override diff --git a/src/client/java/com/minelittlepony/client/render/entities/RenderPonyZombie.java b/src/client/java/com/minelittlepony/client/render/entities/RenderPonyZombie.java index 5a9e655b..ef70e4d2 100644 --- a/src/client/java/com/minelittlepony/client/render/entities/RenderPonyZombie.java +++ b/src/client/java/com/minelittlepony/client/render/entities/RenderPonyZombie.java @@ -1,8 +1,6 @@ package com.minelittlepony.client.render.entities; -import com.minelittlepony.client.model.ModelWrapper; import com.minelittlepony.client.model.entities.ModelZombiePony; -import com.minelittlepony.client.render.RenderPonyMob; import com.mojang.blaze3d.platform.GlStateManager; import net.minecraft.client.render.entity.EntityRenderDispatcher; @@ -19,7 +17,7 @@ public class RenderPonyZombie extends RenderPonyMob public static final Identifier PIGMAN = new Identifier("minelittlepony", "textures/entity/zombie/zombie_pigman_pony.png"); public RenderPonyZombie(EntityRenderDispatcher manager) { - super(manager, new ModelWrapper<>(new ModelZombiePony<>())); + super(manager, new ModelZombiePony<>()); } @Override @@ -61,7 +59,7 @@ public class RenderPonyZombie extends RenderPonyMob public static class Giant extends RenderPonyMob.Caster> { public Giant(EntityRenderDispatcher manager) { - super(manager, new ModelWrapper<>(new ModelZombiePony<>())); + super(manager, new ModelZombiePony<>()); } @Override diff --git a/src/client/java/com/minelittlepony/client/render/entities/RenderPonyZombieVillager.java b/src/client/java/com/minelittlepony/client/render/entities/RenderPonyZombieVillager.java index d686d2fb..addbe04f 100644 --- a/src/client/java/com/minelittlepony/client/render/entities/RenderPonyZombieVillager.java +++ b/src/client/java/com/minelittlepony/client/render/entities/RenderPonyZombieVillager.java @@ -1,8 +1,6 @@ package com.minelittlepony.client.render.entities; -import com.minelittlepony.client.model.ModelWrapper; import com.minelittlepony.client.model.entities.ModelZombieVillagerPony; -import com.minelittlepony.client.render.RenderPonyMob; import com.minelittlepony.util.resources.FormattedTextureSupplier; import com.minelittlepony.util.resources.ITextureSupplier; @@ -22,7 +20,7 @@ public class RenderPonyZombieVillager extends RenderPonyMob.Caster PROFESSIONS = new VillagerProfessionTextureCache(FORMATTER, DEFAULT); public RenderPonyZombieVillager(EntityRenderDispatcher manager) { - super(manager, new ModelWrapper<>(new ModelZombieVillagerPony())); + super(manager, new ModelZombieVillagerPony()); } @Override diff --git a/src/client/java/com/minelittlepony/client/render/entities/player/RenderPonyPlayer.java b/src/client/java/com/minelittlepony/client/render/entities/player/RenderPonyPlayer.java index 17f4e25a..bbf79b92 100644 --- a/src/client/java/com/minelittlepony/client/render/entities/player/RenderPonyPlayer.java +++ b/src/client/java/com/minelittlepony/client/render/entities/player/RenderPonyPlayer.java @@ -36,10 +36,10 @@ public class RenderPonyPlayer extends PlayerEntityRenderer implements IPonyRende protected final RenderPony> renderPony = new RenderPony<>(this); - public RenderPonyPlayer(EntityRenderDispatcher manager, boolean useSmallArms, ModelWrapper> model) { + public RenderPonyPlayer(EntityRenderDispatcher manager, boolean useSmallArms, ClientPonyModel model) { super(manager, useSmallArms); - this.model = renderPony.setPonyModel(model); + this.model = renderPony.setPonyModel(new ModelWrapper<>(model)); addLayers(); } @@ -170,11 +170,6 @@ public class RenderPonyPlayer extends PlayerEntityRenderer implements IPonyRende return renderPony.playerModel; } - @Override - public IPony getEntityPony(AbstractClientPlayerEntity player) { - return MineLittlePony.getInstance().getManager().getPony(player); - } - @Override public RenderPony> getInternalRenderer() { return renderPony; @@ -185,4 +180,9 @@ public class RenderPonyPlayer extends PlayerEntityRenderer implements IPonyRende return getTexture(entity); } + @Override + public IPony getEntityPony(AbstractClientPlayerEntity entity) { + return MineLittlePony.getInstance().getManager().getPony(entity); + } + } diff --git a/src/client/java/com/minelittlepony/client/render/entities/player/RenderSeaponyPlayer.java b/src/client/java/com/minelittlepony/client/render/entities/player/RenderSeaponyPlayer.java index cf341f84..f0a259d7 100644 --- a/src/client/java/com/minelittlepony/client/render/entities/player/RenderSeaponyPlayer.java +++ b/src/client/java/com/minelittlepony/client/render/entities/player/RenderSeaponyPlayer.java @@ -11,16 +11,16 @@ import net.minecraft.particle.ParticleTypes; public class RenderSeaponyPlayer extends RenderPonyPlayer { - protected ModelWrapper> seapony; - protected ModelWrapper> normalPony; + protected final ModelWrapper> seapony; + protected final ModelWrapper> normalPony; public RenderSeaponyPlayer(EntityRenderDispatcher manager, boolean useSmallArms, - ModelWrapper> model, - ModelWrapper> alternate) { + ClientPonyModel model, + ClientPonyModel alternate) { super(manager, useSmallArms, model); - seapony = alternate; - normalPony = model; + seapony = new ModelWrapper<>(alternate); + normalPony = new ModelWrapper<>(model); } @Override diff --git a/src/client/java/com/minelittlepony/client/settings/ClientPonyConfig.java b/src/client/java/com/minelittlepony/client/settings/ClientPonyConfig.java index 161e7cfe..d136fab8 100644 --- a/src/client/java/com/minelittlepony/client/settings/ClientPonyConfig.java +++ b/src/client/java/com/minelittlepony/client/settings/ClientPonyConfig.java @@ -4,7 +4,7 @@ import com.minelittlepony.hdskins.HDSkins; import com.minelittlepony.settings.PonyConfig; import com.minelittlepony.settings.PonyLevel; -public abstract class ClientPonyConfig extends PonyConfig { +public class ClientPonyConfig extends PonyConfig { @Override public void setPonyLevel(PonyLevel ponylevel) { diff --git a/src/client/java/com/minelittlepony/client/transform/PonyPosture.java b/src/client/java/com/minelittlepony/client/transform/PonyPosture.java index 013ee88c..f8ac4bfc 100644 --- a/src/client/java/com/minelittlepony/client/transform/PonyPosture.java +++ b/src/client/java/com/minelittlepony/client/transform/PonyPosture.java @@ -3,9 +3,11 @@ package com.minelittlepony.client.transform; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; -import com.minelittlepony.client.model.ClientPonyModel; +import com.minelittlepony.model.IModel; public interface PonyPosture { + + PonyPosture DEFAULT = new PostureStanding();; PonyPosture ELYTRA = new PostureElytra(); PonyPosture FLIGHT = new PostureFlight(); PonyPosture SWIMMING = new PostureSwimming(); @@ -15,5 +17,15 @@ public interface PonyPosture { return true; } - void transform(ClientPonyModel model, T entity, double motionX, double motionY, double motionZ, float yaw, float ticks); + default void apply(T player, IModel model, float yaw, float ticks, int invert) { + if (applies(player)) { + double motionX = player.x - player.prevX; + double motionY = player.onGround ? 0 : player.y - player.prevY; + double motionZ = player.z - player.prevZ; + + transform(model, player, motionX, invert * motionY, motionZ, yaw, ticks); + } + } + + void transform(IModel model, T entity, double motionX, double motionY, double motionZ, float yaw, float ticks); } diff --git a/src/client/java/com/minelittlepony/client/transform/PostureElytra.java b/src/client/java/com/minelittlepony/client/transform/PostureElytra.java index b4c0a2ae..7a5094b8 100644 --- a/src/client/java/com/minelittlepony/client/transform/PostureElytra.java +++ b/src/client/java/com/minelittlepony/client/transform/PostureElytra.java @@ -2,12 +2,12 @@ package com.minelittlepony.client.transform; import net.minecraft.entity.LivingEntity; -import com.minelittlepony.client.model.ClientPonyModel; +import com.minelittlepony.model.IModel; import com.mojang.blaze3d.platform.GlStateManager; public class PostureElytra implements PonyPosture { @Override - public void transform(ClientPonyModel model, LivingEntity entity, double motionX, double motionY, double motionZ, float yaw, float ticks) { + public void transform(IModel model, LivingEntity entity, double motionX, double motionY, double motionZ, float yaw, float ticks) { GlStateManager.rotatef(90, 1, 0, 0); GlStateManager.translatef(0, entity.isSneaking() ? 0.2F : -1, 0); } diff --git a/src/client/java/com/minelittlepony/client/transform/PostureFalling.java b/src/client/java/com/minelittlepony/client/transform/PostureFalling.java index 204dfae7..7c54a76a 100644 --- a/src/client/java/com/minelittlepony/client/transform/PostureFalling.java +++ b/src/client/java/com/minelittlepony/client/transform/PostureFalling.java @@ -2,11 +2,11 @@ package com.minelittlepony.client.transform; import net.minecraft.entity.LivingEntity; -import com.minelittlepony.client.model.ClientPonyModel; +import com.minelittlepony.model.IModel; public class PostureFalling implements PonyPosture { @Override - public void transform(ClientPonyModel model, LivingEntity entity, double motionX, double motionY, double motionZ, float yaw, float ticks) { + public void transform(IModel model, LivingEntity entity, double motionX, double motionY, double motionZ, float yaw, float ticks) { model.setPitch(0); } } diff --git a/src/client/java/com/minelittlepony/client/transform/PostureFlight.java b/src/client/java/com/minelittlepony/client/transform/PostureFlight.java index 2881fa3d..84f9a19b 100644 --- a/src/client/java/com/minelittlepony/client/transform/PostureFlight.java +++ b/src/client/java/com/minelittlepony/client/transform/PostureFlight.java @@ -1,6 +1,6 @@ package com.minelittlepony.client.transform; -import com.minelittlepony.client.model.ClientPonyModel; +import com.minelittlepony.model.IModel; import com.minelittlepony.util.transform.MotionCompositor; import com.mojang.blaze3d.platform.GlStateManager; @@ -14,7 +14,7 @@ public class PostureFlight extends MotionCompositor implements PonyPosture model, PlayerEntity player, double motionX, double motionY, double motionZ, float yaw, float ticks) { + public void transform(IModel model, PlayerEntity player, double motionX, double motionY, double motionZ, float yaw, float ticks) { model.setPitch((float) calculateIncline(player, motionX, motionY, motionZ)); GlStateManager.rotatef(model.getPitch(), 1, 0, 0); diff --git a/src/client/java/com/minelittlepony/client/transform/PostureStanding.java b/src/client/java/com/minelittlepony/client/transform/PostureStanding.java new file mode 100644 index 00000000..3dcaa9b6 --- /dev/null +++ b/src/client/java/com/minelittlepony/client/transform/PostureStanding.java @@ -0,0 +1,16 @@ +package com.minelittlepony.client.transform; + +import net.minecraft.entity.LivingEntity; + +import com.minelittlepony.model.IModel; + +public class PostureStanding implements PonyPosture { + @Override + public boolean applies(LivingEntity entity) { + return false; + } + + @Override + public void transform(IModel model, LivingEntity entity, double motionX, double motionY, double motionZ, float yaw, float ticks) { + } +} diff --git a/src/main/java/com/minelittlepony/model/IPonyModel.java b/src/main/java/com/minelittlepony/model/IPonyModel.java index 01a3165c..be0f7348 100644 --- a/src/main/java/com/minelittlepony/model/IPonyModel.java +++ b/src/main/java/com/minelittlepony/model/IPonyModel.java @@ -3,6 +3,10 @@ package com.minelittlepony.model; import net.minecraft.client.model.Cuboid; import net.minecraft.entity.LivingEntity; -public interface IPonyModel extends PonyModelConstants, IModel, ICapitated, ICompartmented { +import com.minelittlepony.pony.IPony; +public interface IPonyModel extends PonyModelConstants, IModel, ICapitated, ICompartmented { + default void updateLivingState(T entity, IPony pony) { + + } } diff --git a/src/main/java/com/minelittlepony/settings/PonyConfig.java b/src/main/java/com/minelittlepony/settings/PonyConfig.java index dc17ebec..3f0854ed 100644 --- a/src/main/java/com/minelittlepony/settings/PonyConfig.java +++ b/src/main/java/com/minelittlepony/settings/PonyConfig.java @@ -3,12 +3,11 @@ package com.minelittlepony.settings; import net.minecraft.util.math.MathHelper; import com.google.gson.annotations.Expose; -import com.minelittlepony.common.SensibleConfig; /** * Storage container for MineLP client settings. */ -public abstract class PonyConfig extends SensibleConfig { +public abstract class PonyConfig extends SensibleJsonConfig { @Expose private PonyLevel ponylevel = PonyLevel.PONIES; diff --git a/src/main/java/com/minelittlepony/settings/SensibleJsonConfig.java b/src/main/java/com/minelittlepony/settings/SensibleJsonConfig.java new file mode 100644 index 00000000..1fbdcbd6 --- /dev/null +++ b/src/main/java/com/minelittlepony/settings/SensibleJsonConfig.java @@ -0,0 +1,64 @@ +package com.minelittlepony.settings; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.stream.JsonWriter; +import com.minelittlepony.client.settings.ClientPonyConfig; +import com.minelittlepony.common.SensibleConfig; + +import java.io.BufferedReader; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.function.Supplier; + +public class SensibleJsonConfig extends SensibleConfig { + + static final Gson gson = new GsonBuilder() + .setPrettyPrinting() + .excludeFieldsWithoutExposeAnnotation() + .create(); + + private Path configFile; + + @Override + public void save() { + + try (JsonWriter writer = new JsonWriter(Files.newBufferedWriter(configFile))) { + writer.setIndent(" "); + + gson.toJson(this, ClientPonyConfig.class, writer); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @SuppressWarnings("unchecked") + protected T load(Path file) { + SensibleJsonConfig result = this; + + try { + if (Files.exists(file)) { + try (BufferedReader s = Files.newBufferedReader(file)) { + result = gson.fromJson(s, getClass()); + } catch (IOException ignored) { + result = null; + } + } + + if (result == null) { + result = this; + } + + result.configFile = file; + } finally { + result.save(); + } + + return (T)result; + } + + public static T of(Path file, Supplier creator) { + return creator.get().load(file); + } +}