Skip to content

Commit

Permalink
Better renderer for tall plants
Browse files Browse the repository at this point in the history
  • Loading branch information
Faboslav committed Dec 23, 2022
1 parent 14b4b3a commit a58c6f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static int getNumberOfVariants() {

public static MoobloomVariant getRandomVariant() {
Object[] values = MOOBLOOM_VARIANT_MAP.values().toArray();
return (MoobloomVariant) values[RandomGenerator.generateInt(0, values.length)];
return (MoobloomVariant) values[RandomGenerator.generateInt(0, values.length - 1)];
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.fabricmc.api.Environment;
import net.minecraft.block.BlockState;
import net.minecraft.block.PlantBlock;
import net.minecraft.block.TallFlowerBlock;
import net.minecraft.block.TallPlantBlock;
import net.minecraft.block.enums.DoubleBlockHalf;
import net.minecraft.client.MinecraftClient;
Expand Down Expand Up @@ -51,6 +52,13 @@ public void render(
}

int overlay = LivingEntityRenderer.getOverlay(moobloomEntity, 0.0F);
float scaleFactor = 0.8F;
float yOffset = -0.5F;

if(flower instanceof TallPlantBlock) {
scaleFactor = 0.6F;
yOffset = -0.666F;
}

MinecraftClient minecraftClient = MinecraftClient.getInstance();
boolean renderAsModel = minecraftClient.hasOutline(moobloomEntity) && moobloomEntity.isInvisible();
Expand All @@ -60,30 +68,30 @@ public void render(
matrixStack.push();
this.getContextModel().getHead().rotate(matrixStack);
matrixStack.translate(0.09D, -0.6D, -0.185D);
matrixStack.scale(-0.8F, -0.8F, 0.8F);
matrixStack.translate(-0.5D, -0.5D, -0.5D);
matrixStack.scale(-scaleFactor, -scaleFactor, scaleFactor);
matrixStack.translate(-0.5D, yOffset, -0.5D);
this.renderFlower(matrixStack, vertexConsumerProvider, light, renderAsModel, blockRenderManager, blockState, overlay, bakedModel);
matrixStack.pop();

// Body
matrixStack.push();
matrixStack.translate(0.22D, -0.28D, -0.06D);
matrixStack.scale(-0.8F, -0.8F, 0.8F);
matrixStack.translate(-0.5D, -0.5D, -0.5D);
matrixStack.scale(-scaleFactor, -scaleFactor, scaleFactor);
matrixStack.translate(-0.5D, yOffset, -0.5D);
this.renderFlower(matrixStack, vertexConsumerProvider, light, renderAsModel, blockRenderManager, blockState, overlay, bakedModel);
matrixStack.pop();

matrixStack.push();
matrixStack.translate(-0.2D, -0.22D, 0.01D);
matrixStack.scale(-0.8F, -0.8F, 0.8F);
matrixStack.translate(-0.5D, -0.5D, -0.5D);
matrixStack.scale(-scaleFactor, -scaleFactor, scaleFactor);
matrixStack.translate(-0.5D, yOffset, -0.5D);
this.renderFlower(matrixStack, vertexConsumerProvider, light, renderAsModel, blockRenderManager, blockState, overlay, bakedModel);
matrixStack.pop();

matrixStack.push();
matrixStack.translate(0.03D, -0.28D, 0.47D);
matrixStack.scale(-0.8F, -0.8F, 0.8F);
matrixStack.translate(-0.5D, -0.5D, -0.5D);
matrixStack.scale(-scaleFactor, -scaleFactor, scaleFactor);
matrixStack.translate(-0.5D, yOffset, -0.5D);
this.renderFlower(matrixStack, vertexConsumerProvider, light, renderAsModel, blockRenderManager, blockState, overlay, bakedModel);
matrixStack.pop();
}
Expand Down

0 comments on commit a58c6f8

Please sign in to comment.