From cbaeb9aaca0aece3bc7914907291b01f78284808 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sun, 16 Sep 2018 16:06:56 +0200 Subject: [PATCH] add a hat stack --- .../minelittlepony/model/gear/IStackable.java | 5 ++++ .../com/minelittlepony/model/gear/Muffin.java | 7 ++++- .../minelittlepony/model/gear/Stetson.java | 7 ++++- .../minelittlepony/model/gear/WitchHat.java | 7 ++++- .../render/layer/LayerGear.java | 28 +++++++++++++++---- 5 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/minelittlepony/model/gear/IStackable.java diff --git a/src/main/java/com/minelittlepony/model/gear/IStackable.java b/src/main/java/com/minelittlepony/model/gear/IStackable.java new file mode 100644 index 00000000..8d6e913f --- /dev/null +++ b/src/main/java/com/minelittlepony/model/gear/IStackable.java @@ -0,0 +1,5 @@ +package com.minelittlepony.model.gear; + +public interface IStackable { + float getStackingOffset(); +} diff --git a/src/main/java/com/minelittlepony/model/gear/Muffin.java b/src/main/java/com/minelittlepony/model/gear/Muffin.java index 7e47b811..f8d219e4 100644 --- a/src/main/java/com/minelittlepony/model/gear/Muffin.java +++ b/src/main/java/com/minelittlepony/model/gear/Muffin.java @@ -8,7 +8,7 @@ import com.minelittlepony.model.capabilities.IModel; import com.minelittlepony.pony.data.PonyWearable; import com.minelittlepony.render.model.PonyRenderer; -public class Muffin extends AbstractGear { +public class Muffin extends AbstractGear implements IStackable { private static final ResourceLocation TEXTURE = new ResourceLocation("minelittlepony", "textures/models/muffin.png"); @@ -44,4 +44,9 @@ public class Muffin extends AbstractGear { public ResourceLocation getTexture(Entity entity) { return TEXTURE; } + + @Override + public float getStackingOffset() { + return 0.5F; + } } diff --git a/src/main/java/com/minelittlepony/model/gear/Stetson.java b/src/main/java/com/minelittlepony/model/gear/Stetson.java index 59f2de13..a970e282 100644 --- a/src/main/java/com/minelittlepony/model/gear/Stetson.java +++ b/src/main/java/com/minelittlepony/model/gear/Stetson.java @@ -9,7 +9,7 @@ import com.minelittlepony.pony.data.PonyWearable; import com.minelittlepony.render.model.PlaneRenderer; import com.minelittlepony.render.model.PonyRenderer; -public class Stetson extends AbstractGear { +public class Stetson extends AbstractGear implements IStackable { private static final ResourceLocation TEXTURE = new ResourceLocation("minelittlepony", "textures/models/stetson.png"); private PlaneRenderer rimshot; @@ -49,4 +49,9 @@ public class Stetson extends AbstractGear { public boolean canRender(IModel model, Entity entity) { return model.isWearing(PonyWearable.STETSON); } + + @Override + public float getStackingOffset() { + return 0; + } } diff --git a/src/main/java/com/minelittlepony/model/gear/WitchHat.java b/src/main/java/com/minelittlepony/model/gear/WitchHat.java index 88cb6e73..80a8cb2b 100644 --- a/src/main/java/com/minelittlepony/model/gear/WitchHat.java +++ b/src/main/java/com/minelittlepony/model/gear/WitchHat.java @@ -8,7 +8,7 @@ import com.minelittlepony.model.capabilities.IModel; import com.minelittlepony.pony.data.PonyWearable; import com.minelittlepony.render.model.PonyRenderer; -public class WitchHat extends AbstractGear { +public class WitchHat extends AbstractGear implements IStackable { private static final ResourceLocation WITCH_TEXTURES = new ResourceLocation("textures/entity/witch.png"); @@ -50,4 +50,9 @@ public class WitchHat extends AbstractGear { public ResourceLocation getTexture(Entity entity) { return WITCH_TEXTURES; } + + @Override + public float getStackingOffset() { + return 0.7F; + } } diff --git a/src/main/java/com/minelittlepony/render/layer/LayerGear.java b/src/main/java/com/minelittlepony/render/layer/LayerGear.java index e1536b2b..7bf5fffb 100644 --- a/src/main/java/com/minelittlepony/render/layer/LayerGear.java +++ b/src/main/java/com/minelittlepony/render/layer/LayerGear.java @@ -9,13 +9,17 @@ import org.lwjgl.opengl.GL11; import com.google.common.collect.Lists; import com.minelittlepony.model.AbstractPonyModel; +import com.minelittlepony.model.BodyPart; import com.minelittlepony.model.gear.IGear; +import com.minelittlepony.model.gear.IStackable; import com.minelittlepony.model.gear.Muffin; import com.minelittlepony.model.gear.SaddleBags; import com.minelittlepony.model.gear.Stetson; import com.minelittlepony.model.gear.WitchHat; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class LayerGear extends AbstractPonyLayer { @@ -34,20 +38,35 @@ public class LayerGear extends AbstractPonyLayer protected void doPonyRender(T entity, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale) { AbstractPonyModel model = getPlayerModel(); + Map renderStackingOffsets = new HashMap<>(); + for (IGear gear : gears) { if (gear.canRender(model, entity)) { + GlStateManager.pushMatrix(); + model.transform(gear.getGearLocation()); + gear.getOriginBodyPart(model).postRender(scale); + + if (gear instanceof IStackable) { + BodyPart part = gear.getGearLocation(); + renderStackingOffsets.compute(part, (k, v) -> { + float offset = ((IStackable)gear).getStackingOffset(); + if (v != null) { + GlStateManager.translate(0, -v, 0); + offset += v; + } + return offset; + }); + } + renderGear(model, entity, gear, move, swing, scale, ticks); + GlStateManager.popMatrix(); } } } private void renderGear(AbstractPonyModel model, T entity, IGear gear, float move, float swing, float scale, float ticks) { - GlStateManager.pushMatrix(); GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - model.transform(gear.getGearLocation()); - gear.getOriginBodyPart(model).postRender(scale); - ResourceLocation texture = gear.getTexture(entity); if (texture != null) { getRenderer().bindTexture(texture); @@ -58,6 +77,5 @@ public class LayerGear extends AbstractPonyLayer gear.renderPart(scale); GlStateManager.popAttrib(); - GlStateManager.popMatrix(); } }