Skip to content

Instantly share code, notes, and snippets.

@TechnicianLP
Created July 4, 2017 06:35
Show Gist options
  • Save TechnicianLP/a55b9de550db1bbb186194e98f8f4697 to your computer and use it in GitHub Desktop.
Save TechnicianLP/a55b9de550db1bbb186194e98f8f4697 to your computer and use it in GitHub Desktop.
public class ScaleModel implements IBakedModel {
@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
List<BakedQuad> quads = Lists.newArrayList();
if (state != null && state instanceof IExtendedBlockState) {//ask in irc if you dont know what a extendedblockstate is ...
Float f = ((IExtendedBlockState) state).getValue(YourBlock.scaleProperty); //get the value of the (IUnlisted-) Property for scale
ScaleTransformer transform = new ScaleTransformer().setScale(f); // setup the scaletransformer wit the factor
List<BakedQuad> basic = parent.getQuads(state, side, rand);
for (BakedQuad quad : basic) {
UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(DefaultVertexFormats.BLOCK);//or ITEM if its a item ...
transform.setParent(builder);
quad.pipe(transform);
quads.add(builder.build());
}
}
quads.addAll(othermodel.getQuads(state, side, rand)); // add quads from additional models to the list
return quads;
}
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.client.renderer.vertex.VertexFormatElement;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.client.model.pipeline.IVertexConsumer;
public class ScaleTransformer implements IVertexConsumer {
private IVertexConsumer parent;
private float sx;
private float sy;
private float sz;
@Override
public void put(int element, float... data) {
VertexFormatElement.EnumUsage usage = parent.getVertexFormat().getElement(element).getUsage();
// transform normals and position
if (usage == VertexFormatElement.EnumUsage.POSITION && data.length >= 3) {
float[] dat = new float[3];
dat[0] = data[0] * sx;
dat[1] = data[1] * sy;
dat[2] = data[2] * sz;
data = dat;
} else if (usage == VertexFormatElement.EnumUsage.NORMAL && data.length >= 3) {
float[] dat = new float[3];
dat[0] = data[0] / sx;
dat[1] = data[1] / sy;
dat[2] = data[2] / sz;
data = dat;
}
parent.put(element, data);
}
public ScaleTransformer setScale(float scale) {
sx = sy = sz = scale;
return this;
}
public ScaleTransformer setScale(float sx, float sy, float sz) {
this.sx = sx;
this.sy = sy;
this.sz = sz;
return this;
}
public void setParent(IVertexConsumer parent) {
this.parent = parent;
}
@Override
public VertexFormat getVertexFormat() {
return parent.getVertexFormat();
}
@Override
public void setQuadTint(int tint) {
parent.setQuadTint(tint);
}
@Override
public void setQuadOrientation(EnumFacing orientation) {
parent.setQuadOrientation(orientation);
}
@Override
public void setApplyDiffuseLighting(boolean diffuse) {
parent.setApplyDiffuseLighting(diffuse);
}
@Override
public void setTexture(TextureAtlasSprite texture) {
parent.setTexture(texture);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment