Add value holder object for configs based off the one in tabbychat

This commit is contained in:
Matthew Messinger 2018-07-30 01:27:19 -04:00
parent 1369665fd6
commit 668d7ff6e0
26 changed files with 504 additions and 166 deletions

View file

@ -2,54 +2,71 @@ package com.minelittlepony;
import com.google.gson.annotations.Expose;
import com.minelittlepony.pony.data.PonyLevel;
import com.minelittlepony.settings.SensibleConfig;
import com.minelittlepony.settings.Value;
import com.minelittlepony.settings.ValueConfig;
import com.mumfrey.liteloader.modconfig.ConfigStrategy;
import com.mumfrey.liteloader.modconfig.Exposable;
import com.mumfrey.liteloader.modconfig.ExposableOptions;
import java.util.function.Function;
/**
* Storage container for MineLP client settings.
*
*/
@ExposableOptions(filename = "minelittlepony", strategy = ConfigStrategy.Unversioned)
public class PonyConfig extends SensibleConfig implements Exposable {
public class PonyConfig extends ValueConfig {
@Expose private PonyLevel ponylevel = PonyLevel.PONIES;
@Expose public boolean sizes = true;
@Expose public boolean snuzzles = true;
@Expose public boolean hd = true;
@Expose public boolean showscale = true;
@Expose public boolean fpsmagic = true;
@Expose public boolean ponyskulls = true;
@Expose private final Value<Boolean> sizes = Value.of(true);
@Expose private final Value<Boolean> snuzzles = Value.of(true);
@Expose private final Value<Boolean> hd = Value.of(true);
@Expose private final Value<Boolean> showscale = Value.of(true);
@Expose private final Value<Boolean> fpsmagic = Value.of(true);
@Expose private final Value<Boolean> ponyskulls = Value.of(true);
public enum PonySettings implements Setting {
SIZES,
SNUZZLES,
HD,
SHOWSCALE,
FPSMAGIC,
PONYSKULLS;
@Expose private final Value<Boolean> villagers = Value.of(true);
@Expose private final Value<Boolean> zombies = Value.of(true);
@Expose private final Value<Boolean> pigzombies = Value.of(true);
@Expose private final Value<Boolean> skeletons = Value.of(true);
@Expose private final Value<Boolean> illagers = Value.of(true);
@Expose private final Value<Boolean> guardians = Value.of(true);
public enum PonySettings implements Value<Boolean> {
SIZES(PonyConfig::getSizes),
SNUZZLES(PonyConfig::getSnuzzles),
HD(PonyConfig::getHd),
SHOWSCALE(PonyConfig::getShowscale),
FPSMAGIC(PonyConfig::getFpsmagic),
PONYSKULLS(PonyConfig::getPonyskulls);
private Value<Boolean> config;
PonySettings(Function<PonyConfig, Value<Boolean>> config) {
this.config = config.apply(MineLittlePony.getConfig());
}
@Override
public Boolean get() {
return config.get();
}
@Override
public void set(Boolean value) {
config.set(value);
}
}
@Expose public boolean villagers = true;
@Expose public boolean zombies = true;
@Expose public boolean pigzombies = true;
@Expose public boolean skeletons = true;
@Expose public boolean illagers = true;
@Expose public boolean guardians = true;
/**
* Gets the current PonyLevel. That is the level of ponies you would like to see.
*
* @param ignorePony true to ignore whatever value the setting has.
*/
public PonyLevel getEffectivePonyLevel(boolean ignorePony) {
return ignorePony ? PonyLevel.BOTH : getPonyLevel();
return ignorePony ? PonyLevel.BOTH : ponylevel;
}
/**
* Actually gets the pony level value. No option to ignore reality here.
*/
public PonyLevel getPonyLevel() {
if (ponylevel == null) {
ponylevel = PonyLevel.PONIES;
@ -59,9 +76,58 @@ public class PonyConfig extends SensibleConfig implements Exposable {
/**
* Sets the pony level. Want MOAR PONEHS? Well here you go.
*
* @param ponylevel
*/
public void setPonyLevel(PonyLevel ponylevel) {
this.ponylevel = ponylevel;
}
public Value<Boolean> getSizes() {
return sizes;
}
public Value<Boolean> getSnuzzles() {
return snuzzles;
}
public Value<Boolean> getHd() {
return hd;
}
public Value<Boolean> getShowscale() {
return showscale;
}
public Value<Boolean> getFpsmagic() {
return fpsmagic;
}
public Value<Boolean> getPonyskulls() {
return ponyskulls;
}
public Value<Boolean> getVillagers() {
return villagers;
}
public Value<Boolean> getZombies() {
return zombies;
}
public Value<Boolean> getPigzombies() {
return pigzombies;
}
public Value<Boolean> getSkeletons() {
return skeletons;
}
public Value<Boolean> getIllagers() {
return illagers;
}
public Value<Boolean> getGuardians() {
return guardians;
}
}

View file

@ -1,22 +1,22 @@
package com.minelittlepony.gui;
import com.minelittlepony.settings.Value;
import com.mumfrey.liteloader.client.gui.GuiCheckbox;
import net.minecraft.client.resources.I18n;
public class Checkbox extends GuiCheckbox implements IActionable {
private final IGUIAction<Boolean> action;
private final Value<Boolean> setting;
public Checkbox(int x, int y, String displayString, boolean value, IGUIAction<Boolean> callback) {
public Checkbox(int x, int y, String displayString, Value<Boolean> setting) {
super(0, x, y, I18n.format(displayString));
action = callback;
checked = value;
this.setting = setting;
checked = setting.get();
}
@Override
public void perform() {
checked = action.perform(!checked);
setting.set(checked ^= true);
}
}

View file

@ -1,18 +1,17 @@
package com.minelittlepony.gui;
import java.io.IOException;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.PonyConfig;
import com.minelittlepony.PonyConfig.PonySettings;
import com.minelittlepony.pony.data.PonyLevel;
import com.minelittlepony.render.ponies.MobRenderers;
import com.mumfrey.liteloader.core.LiteLoader;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import java.io.IOException;
/**
* In-Game options menu.
*
@ -46,7 +45,7 @@ public class GuiPonySettings extends GuiScreen {
addButton(new Slider(LEFT, row += 15, 0, 2, config.getPonyLevel().ordinal(), (int id, String name, float value) -> {
return I18n.format(PONY_LEVEL + "." + PonyLevel.valueFor(value).name().toLowerCase());
}, v -> {
PonyLevel level = PonyLevel.valueFor(v);
PonyLevel level = PonyLevel.valueFor((float) v);
config.setPonyLevel(level);
return (float)level.ordinal();
}));
@ -54,7 +53,7 @@ public class GuiPonySettings extends GuiScreen {
row += 15;
addButton(new Label(LEFT, row += 15, OPTIONS_PREFIX + "options", -1));
for (PonySettings i : PonySettings.values()) {
addButton(new Checkbox(LEFT, row += 15, OPTIONS_PREFIX + i.name().toLowerCase(), i.get(), i));
addButton(new Checkbox(LEFT, row += 15, OPTIONS_PREFIX + i.name().toLowerCase(), i));
}
if (mustScroll()) {
@ -65,7 +64,7 @@ public class GuiPonySettings extends GuiScreen {
addButton(new Label(RIGHT, row += 15, MOB_PREFIX + "title", -1));
for (MobRenderers i : MobRenderers.values()) {
addButton(new Checkbox(RIGHT, row += 15, MOB_PREFIX + i.name().toLowerCase(), i.get(), i));
addButton(new Checkbox(RIGHT, row += 15, MOB_PREFIX + i.name().toLowerCase(), i));
}
}

View file

@ -1,15 +0,0 @@
package com.minelittlepony.gui;
/**
* Response actions for UI events.
*/
@FunctionalInterface
public interface IGUIAction<T> {
/**
* Performs this action now.
*
* @param value New Value of the field being changed
* @return Adjusted value the field must take on
*/
T perform(T value);
}

View file

@ -3,11 +3,13 @@ package com.minelittlepony.gui;
import net.minecraft.client.gui.GuiSlider;
import net.minecraft.client.gui.GuiPageButtonList.GuiResponder;
import java.util.function.DoubleUnaryOperator;
public class Slider extends GuiSlider {
private static Responder callback;
public Slider(int x, int y, float minIn, float maxIn, float defaultValue, GuiSlider.FormatHelper formatter, IGUIAction<Float> action) {
public Slider(int x, int y, float minIn, float maxIn, float defaultValue, GuiSlider.FormatHelper formatter, DoubleUnaryOperator action) {
super(callback = new Responder(action), 0, x, y, "", minIn, maxIn, defaultValue, formatter);
callback.owner = this;
callback = null;
@ -15,11 +17,11 @@ public class Slider extends GuiSlider {
private static final class Responder implements GuiResponder {
private final IGUIAction<Float> action;
private final DoubleUnaryOperator action;
private Slider owner;
private Responder(IGUIAction<Float> callback) {
private Responder(DoubleUnaryOperator callback) {
action = callback;
}
@ -28,7 +30,7 @@ public class Slider extends GuiSlider {
@Override
public void setEntryValue(int id, float value) {
owner.setSliderValue(action.perform(value), false);
owner.setSliderValue((float) action.applyAsDouble(value), false);
}
@Override

View file

@ -1,14 +1,12 @@
package com.minelittlepony.model.components;
import com.minelittlepony.pony.data.PonyGender;
import com.minelittlepony.render.plane.PlaneRenderer;
import net.minecraft.client.model.ModelBase;
import static com.minelittlepony.model.PonyModelConstants.*;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.model.capabilities.ICapitated;
import com.minelittlepony.pony.data.PonyGender;
import com.minelittlepony.render.plane.PlaneRenderer;
import net.minecraft.client.model.ModelBase;
public class PonySnout {
@ -59,7 +57,7 @@ public class PonySnout {
}
public void setGender(PonyGender gender) {
boolean show = !head.hasHeadGear() && !isHidden && MineLittlePony.getConfig().snuzzles;
boolean show = !head.hasHeadGear() && !isHidden && MineLittlePony.getConfig().getSnuzzles().get();
mare.isHidden = !show || gender == PonyGender.STALLION;
stallion.isHidden = !show || gender == PonyGender.MARE;

View file

@ -62,7 +62,7 @@ public class PonyData implements IPonyData {
@Override
public PonySize getSize() {
return MineLittlePony.getConfig().sizes ? size : PonySize.NORMAL;
return MineLittlePony.getConfig().getSizes().get() ? size : PonySize.NORMAL;
}
@Override

View file

@ -24,14 +24,14 @@ public enum PonySize implements ITriggerPixelMapped<PonySize> {
}
public float getShadowSize() {
if (MineLittlePony.getConfig().showscale) {
if (MineLittlePony.getConfig().getShowscale().get()) {
return shadowSize * 0.9F;
}
return shadowSize;
}
public float getScaleFactor() {
if (MineLittlePony.getConfig().showscale) {
if (MineLittlePony.getConfig().getShowscale().get()) {
return scale * 0.9F;
}
return scale;

View file

@ -1,13 +1,12 @@
package com.minelittlepony.render;
import org.lwjgl.opengl.GL14;
import static net.minecraft.client.renderer.GlStateManager.*;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.ducks.IRenderItem;
import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.util.coordinates.Color;
import com.mumfrey.liteloader.client.overlays.IMinecraft;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.renderer.ItemRenderer;
@ -17,7 +16,7 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.EnumAction;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHandSide;
import static net.minecraft.client.renderer.GlStateManager.*;
import org.lwjgl.opengl.GL14;
public class LevitatingItemRenderer {
@ -70,7 +69,7 @@ public class LevitatingItemRenderer {
pushMatrix();
boolean doMagic = MineLittlePony.getConfig().fpsmagic && pony.getMetadata().hasMagic();
boolean doMagic = MineLittlePony.getConfig().getFpsmagic().get() && pony.getMetadata().hasMagic();
if (doMagic) {
setupPerspective(entity, stack, left);

View file

@ -1,12 +1,5 @@
package com.minelittlepony.render;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
import org.lwjgl.opengl.GL11;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.PonyConfig;
import com.minelittlepony.ducks.IRenderItem;
@ -18,6 +11,12 @@ import net.minecraft.client.renderer.tileentity.TileEntitySkullRenderer;
import net.minecraft.tileentity.TileEntitySkull;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
/**
* PonySkullRenderer! It renders ponies as skulls, or something...
@ -36,7 +35,7 @@ public class PonySkullRenderer extends TileEntitySkullRenderer implements IRende
* Original/Existing renderer is stored to a backup variable as a fallback in case of mods.
*/
public static TileEntitySkullRenderer resolve() {
if (MineLittlePony.getConfig().ponyskulls) {
if (MineLittlePony.getConfig().getPonyskulls().get()) {
if (!(instance instanceof PonySkullRenderer)) {
backup = instance;
ModUtilities.addRenderer(TileEntitySkull.class, ponyInstance);

View file

@ -1,8 +1,5 @@
package com.minelittlepony.render.player;
import java.util.Map;
import java.util.Optional;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.PonyConfig;
import com.minelittlepony.ducks.IRenderPony;
@ -11,8 +8,8 @@ import com.minelittlepony.model.components.ModelDeadMau5Ears;
import com.minelittlepony.pony.data.Pony;
import com.minelittlepony.pony.data.PonyLevel;
import com.minelittlepony.render.PonySkull;
import com.minelittlepony.render.RenderPony;
import com.minelittlepony.render.PonySkullRenderer.ISkull;
import com.minelittlepony.render.RenderPony;
import com.minelittlepony.render.layer.LayerEntityOnPonyShoulder;
import com.minelittlepony.render.layer.LayerHeldPonyItemMagical;
import com.minelittlepony.render.layer.LayerPonyCape;
@ -22,19 +19,20 @@ import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
import com.voxelmodpack.hdskins.HDSkinManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.client.renderer.entity.layers.LayerArrow;
import net.minecraft.client.resources.DefaultPlayerSkin;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumHandSide;
import net.minecraft.util.ResourceLocation;
import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.client.renderer.entity.layers.LayerArrow;
import net.minecraft.entity.Entity;
import java.util.Map;
import java.util.Optional;
public class RenderPonyPlayer extends RenderPlayer implements IRenderPony<AbstractClientPlayer> {

View file

@ -1,21 +1,37 @@
package com.minelittlepony.render.ponies;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.PonyConfig;
import com.minelittlepony.PonyRenderManager;
import com.minelittlepony.settings.SensibleConfig.Setting;
import com.minelittlepony.settings.Value;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.monster.*;
import net.minecraft.entity.passive.*;
import net.minecraft.entity.monster.EntityElderGuardian;
import net.minecraft.entity.monster.EntityEvoker;
import net.minecraft.entity.monster.EntityGiantZombie;
import net.minecraft.entity.monster.EntityGuardian;
import net.minecraft.entity.monster.EntityHusk;
import net.minecraft.entity.monster.EntityIllusionIllager;
import net.minecraft.entity.monster.EntityPigZombie;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntityStray;
import net.minecraft.entity.monster.EntityVex;
import net.minecraft.entity.monster.EntityVindicator;
import net.minecraft.entity.monster.EntityWitch;
import net.minecraft.entity.monster.EntityWitherSkeleton;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.monster.EntityZombieVillager;
import net.minecraft.entity.passive.EntityVillager;
import java.util.function.Function;
/**
* Central location where new entity renderers are registered and applied.
*
* Due to the limitations in Mumfrey's framework, needs to be paired with a field in PonyConfig.
*/
public enum MobRenderers implements Setting {
VILLAGERS {
public enum MobRenderers implements Value<Boolean> {
VILLAGERS(PonyConfig::getVillagers) {
@Override
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
pony.switchRenderer(state, manager, EntityVillager.class, new RenderPonyVillager(manager));
@ -23,7 +39,7 @@ public enum MobRenderers implements Setting {
pony.switchRenderer(state, manager, EntityZombieVillager.class, new RenderPonyZombieVillager(manager));
}
},
ZOMBIES {
ZOMBIES(PonyConfig::getZombies) {
@Override
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
pony.switchRenderer(state, manager, EntityZombie.class, new RenderPonyZombie<>(manager));
@ -31,13 +47,13 @@ public enum MobRenderers implements Setting {
pony.switchRenderer(state, manager, EntityGiantZombie.class, new RenderPonyZombie.Giant(manager));
}
},
PIGZOMBIES {
PIGZOMBIES(PonyConfig::getPigzombies) {
@Override
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
pony.switchRenderer(state, manager, EntityPigZombie.class, new RenderPonyPigman(manager));
}
},
SKELETONS {
SKELETONS(PonyConfig::getSkeletons) {
@Override
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
pony.switchRenderer(state, manager, EntitySkeleton.class, new RenderPonySkeleton<>(manager));
@ -45,7 +61,7 @@ public enum MobRenderers implements Setting {
pony.switchRenderer(state, manager, EntityWitherSkeleton.class, new RenderPonySkeleton.Wither(manager));
}
},
ILLAGERS {
ILLAGERS(PonyConfig::getIllagers) {
@Override
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
pony.switchRenderer(state, manager, EntityVex.class, new RenderPonyVex(manager));
@ -54,7 +70,7 @@ public enum MobRenderers implements Setting {
pony.switchRenderer(state, manager, EntityIllusionIllager.class, new RenderPonyIllager.Illusionist(manager));
}
},
GUARDIANS {
GUARDIANS(PonyConfig::getGuardians) {
@Override
public void register(boolean state, PonyRenderManager pony, RenderManager manager) {
pony.switchRenderer(state, manager, EntityGuardian.class, new RenderPonyGuardian(manager));
@ -62,14 +78,25 @@ public enum MobRenderers implements Setting {
}
};
private final Value<Boolean> setting;
MobRenderers(Function<PonyConfig, Value<Boolean>> setting) {
this.setting = setting.apply(MineLittlePony.getConfig());
}
@Override
public void set(boolean value) {
Setting.super.set(value);
public Boolean get() {
return setting.get();
}
@Override
public void set(Boolean value) {
setting.set(value);
apply(MineLittlePony.getInstance().getRenderManager(), Minecraft.getMinecraft().getRenderManager());
}
public void apply(PonyRenderManager pony, RenderManager manager) {
boolean state = get();
boolean state = setting.get();
register(state, pony, manager);
if (state) {
MineLittlePony.logger.info(name() + " are now ponies.");

View file

@ -25,7 +25,7 @@ public class RenderPonySkeleton<Skeleton extends AbstractSkeleton> extends Rende
public static final ISkull SKULL = new PonySkull() {
@Override
public boolean canRender(PonyConfig config) {
return config.skeletons;
return config.getSkeletons().get();
}
@Override
@ -73,7 +73,7 @@ public class RenderPonySkeleton<Skeleton extends AbstractSkeleton> extends Rende
public static final ISkull SKULL = new PonySkull() {
@Override
public boolean canRender(PonyConfig config) {
return config.skeletons;
return config.getSkeletons().get();
}
@Override

View file

@ -22,7 +22,7 @@ public class RenderPonyZombie<Zombie extends EntityZombie> extends RenderPonyMob
public static final ISkull SKULL = new PonySkull() {
@Override
public boolean canRender(PonyConfig config) {
return config.zombies;
return config.getZombies().get();
}
@Override

View file

@ -0,0 +1,17 @@
package com.minelittlepony.render.transform;
import com.minelittlepony.model.AbstractPonyModel;
import net.minecraft.entity.EntityLivingBase;
public interface PonyPosture<T extends EntityLivingBase> {
PonyPosture<EntityLivingBase> ELYTRA = new PostureElytra();
PonyPosture<? extends EntityLivingBase> FLIGHT = new PostureFlight();
PonyPosture<? extends EntityLivingBase> SWIMMING = new PostureSwimming();
PonyPosture<EntityLivingBase> FALLING = new PostureFalling();
default boolean applies(EntityLivingBase entity) {
return true;
}
void transform(AbstractPonyModel model, T entity, double motionX, double motionY, double motionZ, float pitch, float yaw, float ticks);
}

View file

@ -0,0 +1,108 @@
package com.minelittlepony.render.transform;
import static net.minecraft.client.renderer.GlStateManager.scale;
import static net.minecraft.client.renderer.GlStateManager.translate;
import com.minelittlepony.model.BodyPart;
import com.minelittlepony.model.capabilities.IModel;
public enum PonyTransformation {
NORMAL {
@Override
public void transform(IModel model, BodyPart part) {
if (model.isSleeping()) translate(0, -0.61F, 0);
switch (part) {
case NECK:
if (model.isCrouching()) translate(-0.03F, 0.03F, 0.1F);
default:
}
}
},
LARGE {
@Override
public void transform(IModel model, BodyPart part) {
if (model.isSleeping()) translate(0, -0.98F, 0.2F);
switch (part) {
case NECK:
translate(0, -0.15F, -0.07F);
if (model.isCrouching()) translate(-0.03F, 0.16F, 0.07F);
break;
case HEAD:
translate(0, -0.17F, -0.04F);
if (model.isSleeping()) translate(0, 0, -0.1F);
if (model.isCrouching()) translate(0, 0.15F, 0);
break;
case BODY:
translate(0, -0.2F, -0.04F);
scale(1.15F, 1.2F, 1.2F);
break;
case TAIL:
translate(0, -0.2F, 0.08F);
break;
case LEGS:
translate(0, -0.14F, 0);
scale(1.15F, 1.12F, 1.15F);
break;
}
}
},
FOAL {
@Override
public void transform(IModel model, BodyPart part) {
if (model.isCrouching()) translate(0, -0.3F, 0);
if (model.isSleeping()) translate(0, -0.6F, -0.5F);
if (model.isRiding()) translate(0, -0.4F, 0);
translate(0, 0.2F, 0);
switch (part) {
case NECK:
scale(1.3F, 1.3F, 1.3F);
if (model.isCrouching()) translate(0, -0.01F, 0.15F);
break;
case HEAD:
scale(1.3F, 1.3F, 1.3F);
break;
case LEGS:
translate(0, 0.1F, 0);
scale(1, 0.81F, 1);
break;
default:
}
}
},
TALL {
@Override
public void transform(IModel model, BodyPart part) {
if (model.isSleeping()) translate(0, -0.5F, 0.25F);
switch (part) {
case NECK:
translate(0, -0.09F, -0.01F);
scale(1, 1.1F, 1);
if (model.isCrouching()) translate(-0.02F, -0.02F, 0.1F);
break;
case HEAD:
translate(0, -0.15F, 0.01F);
if (model.isCrouching()) translate(0, 0.05F, 0);
break;
case BODY:
translate(0, -0.1F, 0);
break;
case TAIL:
translate(0, -0.1F, 0);
break;
case LEGS:
translate(0, -0.25F, 0.03F);
scale(1, 1.18F, 1);
if (model.isGoingFast()) translate(0, 0.05F, 0);
break;
}
}
};
public abstract void transform(IModel model, BodyPart part);
}

View file

@ -0,0 +1,13 @@
package com.minelittlepony.render.transform;
import com.minelittlepony.model.AbstractPonyModel;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.EntityLivingBase;
public class PostureElytra implements PonyPosture<EntityLivingBase> {
@Override
public void transform(AbstractPonyModel model, EntityLivingBase entity, double motionX, double motionY, double motionZ, float pitch, float yaw, float ticks) {
GlStateManager.rotate(90, 1, 0, 0);
GlStateManager.translate(0, entity.isSneaking() ? 0.2F : -1, 0);
}
}

View file

@ -0,0 +1,11 @@
package com.minelittlepony.render.transform;
import com.minelittlepony.model.AbstractPonyModel;
import net.minecraft.entity.EntityLivingBase;
public class PostureFalling implements PonyPosture<EntityLivingBase> {
@Override
public void transform(AbstractPonyModel model, EntityLivingBase entity, double motionX, double motionY, double motionZ, float pitch, float yaw, float ticks) {
model.motionPitch = 0;
}
}

View file

@ -0,0 +1,65 @@
package com.minelittlepony.render.transform;
import com.minelittlepony.model.AbstractPonyModel;
import com.minelittlepony.util.math.MathUtil;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.math.MathHelper;
public class PostureFlight implements PonyPosture<AbstractClientPlayer> {
@Override
public boolean applies(EntityLivingBase entity) {
return entity instanceof AbstractClientPlayer;
}
protected double calculateRoll(AbstractClientPlayer player, double motionX, double motionY, double motionZ) {
// since model roll should probably be calculated from model rotation rather than entity rotation...
double roll = MathUtil.sensibleAngle(player.prevRenderYawOffset - player.renderYawOffset);
double horMotion = Math.sqrt(motionX * motionX + motionZ * motionZ);
float modelYaw = MathUtil.sensibleAngle(player.renderYawOffset);
// detecting that we're flying backwards and roll must be inverted
if (Math.abs(MathUtil.sensibleAngle((float) Math.toDegrees(Math.atan2(motionX, motionZ)) + modelYaw)) > 90) {
roll *= -1;
}
// ayyy magic numbers (after 5 - an approximation of nice looking coefficients calculated by hand)
// roll might be zero, in which case Math.pow produces +Infinity. Anything x Infinity = NaN.
double pow = roll != 0 ? Math.pow(Math.abs(roll), -0.191) : 0;
roll *= horMotion * 5 * (3.6884f * pow);
assert !Float.isNaN((float)roll);
return MathHelper.clamp(roll, -54, 54);
}
protected double calculateIncline(AbstractClientPlayer player, double motionX, double motionY, double motionZ) {
double dist = Math.sqrt(motionX * motionX + motionZ * motionZ);
double angle = Math.atan2(motionY, dist);
if (!player.capabilities.isFlying) {
angle /= 2;
}
angle = MathUtil.clampLimit(angle, Math.PI / 3);
return Math.toDegrees(angle);
}
@Override
public void transform(AbstractPonyModel model, AbstractClientPlayer player, double motionX, double motionY, double motionZ, float pitch, float yaw, float ticks) {
model.motionPitch = (float) calculateIncline(player, motionX, motionY, motionZ);
GlStateManager.rotate(model.motionPitch, 1, 0, 0);
float roll = (float)calculateRoll(player, motionX, motionY, motionZ);
roll = model.getMetadata().getInterpolator().interpolate("pegasusRoll", roll, 10);
GlStateManager.rotate((float)roll, 0, 0, 1);
}
}

View file

@ -0,0 +1,20 @@
package com.minelittlepony.render.transform;
import net.minecraft.client.entity.AbstractClientPlayer;
public class PostureSwimming extends PostureFlight {
@Override
protected double calculateRoll(AbstractClientPlayer player, double motionX, double motionY, double motionZ) {
motionX *= 2;
motionZ *= 2;
return super.calculateRoll(player, motionX, motionY, motionZ);
}
@Override
protected double calculateIncline(AbstractClientPlayer player, double motionX, double motionY, double motionZ) {
return super.calculateIncline(player, motionX, motionY, motionZ);
}
}

View file

@ -0,0 +1,8 @@
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
package com.minelittlepony.render.transform;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -0,0 +1,20 @@
package com.minelittlepony.settings;
public class BaseValue<T> implements Value<T> {
private T value;
public BaseValue(T value) {
this.value = value;
}
@Override
public T get() {
return value;
}
@Override
public void set(T value) {
this.value = value;
}
}

View file

@ -1,60 +0,0 @@
package com.minelittlepony.settings;
import com.minelittlepony.gui.IGUIAction;
/**
* A sensible config container that actually lets us programatically index values by a key.
*
* Reflection because Mumfrey pls.
*
*/
// Mumfrey pls.
public abstract class SensibleConfig {
private static SensibleConfig instance;
public SensibleConfig() {
instance = this;
}
public interface Setting extends IGUIAction<Boolean> {
String name();
/**
* Gets the config value associated with this entry.
*/
default boolean get() {
return instance.getValue(this);
}
/**
* Sets the config value associated with this entry.
*/
default void set(boolean value) {
instance.setValue(this, value);
}
@Override
default Boolean perform(Boolean v) {
set(v);
return v;
}
}
public boolean getValue(Setting key) {
try {
return this.getClass().getField(key.name().toLowerCase()).getBoolean(this);
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignored) {
return true;
}
}
public boolean setValue(Setting key, boolean value) {
try {
this.getClass().getField(key.name().toLowerCase()).setBoolean(this, value);
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException ignored) {
}
return value;
}
}

View file

@ -0,0 +1,12 @@
package com.minelittlepony.settings;
public interface Value<T> {
T get();
void set(T value);
static <T> Value<T> of(T value) {
return new BaseValue<>(value);
}
}

View file

@ -0,0 +1,26 @@
package com.minelittlepony.settings;
import com.google.gson.GsonBuilder;
import com.mumfrey.liteloader.modconfig.AdvancedExposable;
import java.io.File;
/**
* A sensible config container that actually lets us programatically index values by a key.
*
* Reflection because Mumfrey pls.
*
*/
// Mumfrey pls.
public class ValueConfig implements AdvancedExposable {
@Override
public void setupGsonSerialiser(GsonBuilder gsonBuilder) {
gsonBuilder.registerTypeAdapter(Value.class, new ValueSerializer());
}
@Override
public File getConfigFile(File configFile, File configFileLocation, String defaultFileName) {
return null;
}
}

View file

@ -0,0 +1,25 @@
package com.minelittlepony.settings;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
public class ValueSerializer implements JsonSerializer<Value<?>>, JsonDeserializer<Value<?>> {
@Override
public Value<?> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
ParameterizedType type = (ParameterizedType) typeOfT;
return Value.of(context.deserialize(json, type.getActualTypeArguments()[0]));
}
@Override
public JsonElement serialize(Value<?> src, Type typeOfSrc, JsonSerializationContext context) {
return context.serialize(src.get());
}
}