mirror of
https://github.com/MineLittlePony/MineLittlePony.git
synced 2024-11-22 20:47:59 +01:00
add a hat stack
This commit is contained in:
parent
891df59dfc
commit
cbaeb9aaca
5 changed files with 46 additions and 8 deletions
|
@ -0,0 +1,5 @@
|
||||||
|
package com.minelittlepony.model.gear;
|
||||||
|
|
||||||
|
public interface IStackable {
|
||||||
|
float getStackingOffset();
|
||||||
|
}
|
|
@ -8,7 +8,7 @@ import com.minelittlepony.model.capabilities.IModel;
|
||||||
import com.minelittlepony.pony.data.PonyWearable;
|
import com.minelittlepony.pony.data.PonyWearable;
|
||||||
import com.minelittlepony.render.model.PonyRenderer;
|
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");
|
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) {
|
public ResourceLocation getTexture(Entity entity) {
|
||||||
return TEXTURE;
|
return TEXTURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getStackingOffset() {
|
||||||
|
return 0.5F;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import com.minelittlepony.pony.data.PonyWearable;
|
||||||
import com.minelittlepony.render.model.PlaneRenderer;
|
import com.minelittlepony.render.model.PlaneRenderer;
|
||||||
import com.minelittlepony.render.model.PonyRenderer;
|
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 static final ResourceLocation TEXTURE = new ResourceLocation("minelittlepony", "textures/models/stetson.png");
|
||||||
|
|
||||||
private PlaneRenderer rimshot;
|
private PlaneRenderer rimshot;
|
||||||
|
@ -49,4 +49,9 @@ public class Stetson extends AbstractGear {
|
||||||
public boolean canRender(IModel model, Entity entity) {
|
public boolean canRender(IModel model, Entity entity) {
|
||||||
return model.isWearing(PonyWearable.STETSON);
|
return model.isWearing(PonyWearable.STETSON);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getStackingOffset() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import com.minelittlepony.model.capabilities.IModel;
|
||||||
import com.minelittlepony.pony.data.PonyWearable;
|
import com.minelittlepony.pony.data.PonyWearable;
|
||||||
import com.minelittlepony.render.model.PonyRenderer;
|
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");
|
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) {
|
public ResourceLocation getTexture(Entity entity) {
|
||||||
return WITCH_TEXTURES;
|
return WITCH_TEXTURES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getStackingOffset() {
|
||||||
|
return 0.7F;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,17 @@ import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.minelittlepony.model.AbstractPonyModel;
|
import com.minelittlepony.model.AbstractPonyModel;
|
||||||
|
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.Muffin;
|
import com.minelittlepony.model.gear.Muffin;
|
||||||
import com.minelittlepony.model.gear.SaddleBags;
|
import com.minelittlepony.model.gear.SaddleBags;
|
||||||
import com.minelittlepony.model.gear.Stetson;
|
import com.minelittlepony.model.gear.Stetson;
|
||||||
import com.minelittlepony.model.gear.WitchHat;
|
import com.minelittlepony.model.gear.WitchHat;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class LayerGear<T extends EntityLivingBase> extends AbstractPonyLayer<T> {
|
public class LayerGear<T extends EntityLivingBase> extends AbstractPonyLayer<T> {
|
||||||
|
|
||||||
|
@ -34,20 +38,35 @@ public class LayerGear<T extends EntityLivingBase> extends AbstractPonyLayer<T>
|
||||||
protected void doPonyRender(T entity, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale) {
|
protected void doPonyRender(T entity, float move, float swing, float partialTicks, float ticks, float headYaw, float headPitch, float scale) {
|
||||||
AbstractPonyModel model = getPlayerModel();
|
AbstractPonyModel model = getPlayerModel();
|
||||||
|
|
||||||
|
Map<BodyPart, Float> renderStackingOffsets = new HashMap<>();
|
||||||
|
|
||||||
for (IGear gear : gears) {
|
for (IGear gear : gears) {
|
||||||
if (gear.canRender(model, entity)) {
|
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);
|
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) {
|
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);
|
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
|
||||||
|
|
||||||
model.transform(gear.getGearLocation());
|
|
||||||
gear.getOriginBodyPart(model).postRender(scale);
|
|
||||||
|
|
||||||
ResourceLocation texture = gear.getTexture(entity);
|
ResourceLocation texture = gear.getTexture(entity);
|
||||||
if (texture != null) {
|
if (texture != null) {
|
||||||
getRenderer().bindTexture(texture);
|
getRenderer().bindTexture(texture);
|
||||||
|
@ -58,6 +77,5 @@ public class LayerGear<T extends EntityLivingBase> extends AbstractPonyLayer<T>
|
||||||
gear.renderPart(scale);
|
gear.renderPart(scale);
|
||||||
|
|
||||||
GlStateManager.popAttrib();
|
GlStateManager.popAttrib();
|
||||||
GlStateManager.popMatrix();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue