Java Code Examples for net.minecraft.client.util.math.MatrixStack#translate()

The following examples show how to use net.minecraft.client.util.math.MatrixStack#translate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TinyPumpkinRenderer.java    From the-hallow with MIT License 6 votes vote down vote up
@Override
public void render(TinyPumpkinBlockEntity pumpkin, float f, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j) {
	ItemRenderer renderer = MinecraftClient.getInstance().getItemRenderer();
	
	matrixStack.push();
	matrixStack.translate(0.5, 0.275, 0.5);
	matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(360 - pumpkin.getCachedState().get(HorizontalFacingBlock.FACING).asRotation()));
	matrixStack.multiply(NINETY_DEG_X);
	matrixStack.scale(0.75f, 0.75f, 0.75f);
	
	matrixStack.push();
	matrixStack.translate(0.25, 0, 0);
	matrixStack.multiply(MINUS_NINETY_DEG_Y);
	renderer.renderItem(pumpkin.getLeftItem(), ModelTransformation.Mode.FIXED, i, j, matrixStack, vertexConsumerProvider);
	matrixStack.pop();
	
	matrixStack.push();
	matrixStack.translate(-0.25, 0, 0);
	matrixStack.multiply(MINUS_NINETY_DEG_Y);
	renderer.renderItem(pumpkin.getRightItem(), ModelTransformation.Mode.FIXED, i, j, matrixStack, vertexConsumerProvider);
	matrixStack.pop();
	
	matrixStack.pop();
}
 
Example 2
Source File: EquineRenderManager.java    From MineLittlePony with MIT License 6 votes vote down vote up
protected void translateRider(T entity, MatrixStack stack, float ticks) {
    if (entity.hasVehicle() && entity.getVehicle() instanceof LivingEntity) {

        LivingEntity ridingEntity = (LivingEntity) entity.getVehicle();
        IPonyRenderContext<LivingEntity, ?> renderer = PonyRenderDispatcher.getInstance().getPonyRenderer(ridingEntity);

        if (renderer != null) {
            // negate vanilla translations so the rider begins at the ridees feet.
            stack.translate(0, -ridingEntity.getHeight(), 0);

            IPony riderPony = renderer.getEntityPony(ridingEntity);

            renderer.translateRider(ridingEntity, riderPony, entity, pony, stack, ticks);
        }
    }
}
 
Example 3
Source File: PonyRenderer.java    From MineLittlePony with MIT License 6 votes vote down vote up
@Override
protected void setupTransforms(T entity, MatrixStack stack, float ageInTicks, float rotationYaw, float partialTicks) {
    manager.preRenderCallback(entity, stack, partialTicks);
    if (getModel() instanceof PlayerEntityModel) {
        ((PlayerEntityModel<?>)getModel()).setVisible(true);
    }

    if (getModel().getAttributes().isSitting) {
        stack.translate(0, 0.125D, 0);
    }

    rotationYaw = manager.getRenderYaw(entity, rotationYaw, partialTicks);
    super.setupTransforms(entity, stack, ageInTicks, rotationYaw, partialTicks);

    manager.applyPostureTransform(entity, stack, rotationYaw, partialTicks);
}
 
Example 4
Source File: IllagerPonyRenderer.java    From MineLittlePony with MIT License 6 votes vote down vote up
@Override
public void render(IllusionerEntity entity, float entityYaw, float tickDelta, MatrixStack stack, VertexConsumerProvider renderContext, int lightUv) {
    if (entity.isInvisible()) {
        Vec3d[] clones = entity.method_7065(tickDelta);
        float rotation = getAnimationProgress(entity, tickDelta);

        for (int i = 0; i < clones.length; ++i) {
            stack.push();
            stack.translate(
                    clones[i].x + MathHelper.cos(i + rotation * 0.5F) * 0.025D,
                    clones[i].y + MathHelper.cos(i + rotation * 0.75F) * 0.0125D,
                    clones[i].z + MathHelper.cos(i + rotation * 0.7F) * 0.025D
            );
            super.render(entity, entityYaw, tickDelta, stack, renderContext, lightUv);
            stack.pop();
        }
    } else {
        super.render(entity, entityYaw, tickDelta, stack, renderContext, lightUv);
    }
}
 
Example 5
Source File: HallowedTreasureChestEntityRenderer.java    From the-hallow with MIT License 6 votes vote down vote up
@Override
public void render(HallowedTreasureChestEntity chest, float yaw, float tickDelta, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int light) {
	matrixStack.push();
	
	// initial size and position
	matrixStack.translate(-0.275, 0.57, 0.275);
	matrixStack.multiply(INITIAL_ROTATION_X);
	matrixStack.scale(0.57f, 0.57f, 0.57f);
	
	// calculate interpolated render rotation from last rotation
	float interpolated = chest.previousRotation + (chest.rotation - chest.previousRotation) * tickDelta;
	
	matrixStack.translate(0.5, 0.5, 0.5);
	matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(interpolated));
	matrixStack.translate(-0.5, -0.5, -0.5);
	
	// jiggle after finishing spin
	if (chest.getEndProgress() != 0) {
		matrixStack.translate(0.5, 0.5, 0.5);
		matrixStack.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion((float) MathHelper.sin(chest.getEndProgress())));
		matrixStack.translate(-0.5f, -0.5f, -0.5f);
	}
	
	
	// render chest
	updateHingeProgress(chest, chestModel);
	chestModel.render(matrixStack, vertexConsumerProvider.getBuffer(RenderLayer.getEntityCutout(TEXTURE)), light, OverlayTexture.DEFAULT_UV, 1f, 1f, 1f, 1f);
	
	
	// finish
	matrixStack.pop();
}
 
Example 6
Source File: PonySkullRenderer.java    From MineLittlePony with MIT License 6 votes vote down vote up
static void handleRotation(MatrixStack stack, @Nullable Direction direction) {
    if (direction == null) {
        stack.translate(0.5, 0, 0.5);
        return;
    }

    switch (direction) {
        case NORTH:
            stack.translate(0.5, 0.25, 0.74);
            break;
        case SOUTH:
            stack.translate(0.5, 0.25, 0.26);
            break;
        case WEST:
            stack.translate(0.74, 0.25, 0.5);
            break;
        case EAST:
        default:
            stack.translate(0.26, 0.25, 0.5);
            break;
    }
}
 
Example 7
Source File: SkirtCostumeItem.java    From the-hallow with MIT License 6 votes vote down vote up
@Override
@Environment(EnvType.CLIENT)
public void render(String slot, MatrixStack matrix, VertexConsumerProvider vertexConsumer, int light, PlayerEntityModel<AbstractClientPlayerEntity> model, AbstractClientPlayerEntity player, float headYaw, float headPitch) {
	ItemRenderer renderer = MinecraftClient.getInstance().getItemRenderer();
	matrix.push();
	translateToChest(model, player, headYaw, headPitch, matrix); //TODO switch back to trinkets version once it's fixed
	matrix.push();
	matrix.translate(0.25, 0.65, 0);
	matrix.scale(0.5F, 0.5F, 0.5F);
	matrix.multiply(ROTATION_CONSTANT);
	renderer.renderItem(new ItemStack(Items.BLAZE_ROD), ModelTransformation.Mode.FIXED, light, OverlayTexture.DEFAULT_UV, matrix, vertexConsumer);
	matrix.pop();
	matrix.push();
	matrix.translate(-0.25, 0.65, 0);
	matrix.scale(0.5F, 0.5F, 0.5F);
	matrix.multiply(ROTATION_CONSTANT);
	renderer.renderItem(new ItemStack(Items.BLAZE_ROD), ModelTransformation.Mode.FIXED, light, OverlayTexture.DEFAULT_UV, matrix, vertexConsumer);
	matrix.pop();
	matrix.push();
	matrix.translate(0, 0.65, 0.325);
	matrix.scale(0.5F, 0.5F, 0.5F);
	matrix.multiply(ROTATION_CONSTANT);
	renderer.renderItem(new ItemStack(Items.BLAZE_ROD), ModelTransformation.Mode.FIXED, light, OverlayTexture.DEFAULT_UV, matrix, vertexConsumer);
	matrix.pop();
	matrix.pop();
}
 
Example 8
Source File: ZebraModel.java    From MineLittlePony with MIT License 5 votes vote down vote up
static void applyLongNeck(BodyPart part, MatrixStack stack) {
    if (part == BodyPart.HEAD || part == BodyPart.NECK) {
        stack.translate(0, -0.1F, 0);
    }
    if (part == BodyPart.NECK) {
         stack.scale(1, 1.3F, 1);
    }
}
 
Example 9
Source File: LevitatingItemRenderer.java    From MineLittlePony with MIT License 5 votes vote down vote up
/**
 * Moves held items to look like they're floating in the player's field.
 */
private void setupPerspective(ItemRenderer renderer, LivingEntity entity, ItemStack item, boolean left, MatrixStack stack) {
    UseAction action = item.getUseAction();

    boolean doNormal = entity.getItemUseTime() <= 0 || action == UseAction.NONE || action == UseAction.CROSSBOW;

    if (doNormal) { // eating, blocking, and drinking are not transformed. Only held items.
        int sign = left ? 1 : -1;
        float ticks = entity.age * sign;

        float floatAmount = -(float)Math.sin(ticks / 9F) / 40F;
        float driftAmount = -(float)Math.cos(ticks / 6F) / 40F;

        boolean handHeldTool =
                   action == UseAction.BOW
                || action == UseAction.CROSSBOW
                || action == UseAction.BLOCK;

        float distanceChange = handHeldTool ? -0.3F : -0.6F;

        stack.translate(
                driftAmount - floatAmount / 4F + distanceChange / 1.5F * sign,
                floatAmount,
                distanceChange);

        if (!handHeldTool) { // bows have to point forwards
            stack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(sign * -60 + floatAmount));
            stack.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(sign * 30 + driftAmount));
        }
    }
}
 
Example 10
Source File: HallowCharmItem.java    From the-hallow with MIT License 5 votes vote down vote up
public static void translateToChest(PlayerEntityModel<AbstractClientPlayerEntity> model, AbstractClientPlayerEntity player, float headYaw, float headPitch, MatrixStack matrix) {
	if (player.isInSneakingPose() && !model.riding && !player.isSwimming()) {
		matrix.translate(0, 0.2, 0);
		matrix.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(model.torso.pitch * 57.5f));
	}
	matrix.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(model.torso.yaw * 57.5f));
	matrix.translate(0, 0.4, -0.16);
}
 
Example 11
Source File: HallowCharmItem.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public void render(String slot, MatrixStack matrix, VertexConsumerProvider vertexConsumer, int light, PlayerEntityModel<AbstractClientPlayerEntity> model, AbstractClientPlayerEntity player, float headYaw, float headPitch) {
	ItemRenderer renderer = MinecraftClient.getInstance().getItemRenderer();
	matrix.push();
	translateToChest(model, player, headYaw, headPitch, matrix); //TODO switch back to trinkets version once it's fixed
	matrix.translate(0, -0.15, 0);
	matrix.scale(0.5F, 0.5F, 0.5F);
	matrix.multiply(ROTATION_CONSTANT);
	renderer.renderItem(new ItemStack(HallowedItems.HALLOW_CHARM), ModelTransformation.Mode.FIXED, light, OverlayTexture.DEFAULT_UV, matrix, vertexConsumer);
	matrix.pop();
}
 
Example 12
Source File: PlayerPonyRenderer.java    From MineLittlePony with MIT License 5 votes vote down vote up
@Override
protected void renderLabelIfPresent(AbstractClientPlayerEntity entity, Text name, MatrixStack stack, VertexConsumerProvider renderContext, int maxDistance) {
    stack.push();

    if (entity.isSleeping()) {
        if (entity.getSleepingPosition().isPresent() && entity.getEntityWorld().getBlockState(entity.getSleepingPosition().get()).getBlock() instanceof BedBlock) {
            double bedRad = Math.toRadians(entity.getSleepingDirection().asRotation());

            stack.translate(Math.cos(bedRad), 0, -Math.sin(bedRad));
        }
    }
    stack.translate(0, manager.getNamePlateYOffset(entity), 0);
    super.renderLabelIfPresent(entity, name, stack, renderContext, maxDistance);
    stack.pop();
}
 
Example 13
Source File: EnderStallionModel.java    From MineLittlePony with MIT License 5 votes vote down vote up
@Override
public void render(MatrixStack stack, VertexConsumer vertices, int overlayUv, int lightUv, float red, float green, float blue, float alpha) {
    stack.push();
    stack.translate(0, -1.15F, 0);
    super.render(stack, vertices, overlayUv, lightUv, red, green, blue, alpha);
    stack.pop();
}
 
Example 14
Source File: PlayerPonyRenderer.java    From MineLittlePony with MIT License 5 votes vote down vote up
@Override
protected void scale(AbstractClientPlayerEntity entity, MatrixStack stack, float tickDelta) {
    if (getModel() instanceof PlayerEntityModel) {
        ((PlayerEntityModel<?>)getModel()).setVisible(true);
    }

    if (manager.getModel().getAttributes().isSitting) {
        stack.translate(0, entity.getHeightOffset(), 0);
    }
}
 
Example 15
Source File: WitchRenderer.java    From MineLittlePony with MIT License 5 votes vote down vote up
@Override
protected HeldItemFeature<WitchEntity, WitchPonyModel> createItemHoldingLayer() {
    return new HeldItemFeature<WitchEntity, WitchPonyModel>(this) {
        @Override
        protected void preItemRender(WitchEntity entity, ItemStack drop, ModelTransformation.Mode transform, Arm hand, MatrixStack stack) {
            stack.translate(0, -0.3F, -0.8F);
            stack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(10));
        }
    };
}
 
Example 16
Source File: BasicSolarPanelBlockEntityRenderer.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
public void render(MatrixStack matrices, VertexConsumer vertexConsumer, int light, int overlay, float red, float green, float blue, float alpha) {
    this.pole.render(matrices, vertexConsumer, light, overlay, red, green, blue, alpha);
    matrices.translate(0.0F, 1.5F, 0.0F);

    matrices.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(180.0F));
    matrices.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(-90.0F));

    this.renderPanel(matrices, vertexConsumer, light, overlay, red, green, blue, alpha);
}
 
Example 17
Source File: ElytraFeature.java    From MineLittlePony with MIT License 4 votes vote down vote up
protected void preRenderCallback(MatrixStack stack) {
    M body = getModelWrapper().getBody();
    stack.translate(0, body.getRiderYOffset(), 0.125);
    body.transform(BodyPart.BODY, stack);
}
 
Example 18
Source File: SeaponyModel.java    From MineLittlePony with MIT License 4 votes vote down vote up
@Override
public void transform(BodyPart part, MatrixStack stack) {
    stack.translate(0, 0.6F, 0);

    super.transform(part, stack);
}
 
Example 19
Source File: EntityRendererMixin.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Copy of renderLabelIfPresent() since calling the original would result in
 * an infinite loop. Also makes it easier to modify.
 */
protected void wurstRenderLabelIfPresent(T entity, Text text,
	MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider,
	int i)
{
	double d = this.dispatcher.getSquaredDistanceToCamera(entity);
	
	if(d > 4096)
		return;
	
	NameTagsHack nameTagsHack = WurstClient.INSTANCE.getHax().nameTagsHack;
	
	boolean bl = !entity.isSneaky() || nameTagsHack.isEnabled();
	float f = entity.getHeight() + 0.5F;
	int j = "deadmau5".equals(text.getString()) ? -10 : 0;
	
	matrixStack.push();
	matrixStack.translate(0.0D, f, 0.0D);
	matrixStack.multiply(this.dispatcher.getRotation());
	
	float scale = 0.025F;
	if(nameTagsHack.isEnabled())
	{
		double distance = WurstClient.MC.player.distanceTo(entity);
		
		if(distance > 10)
			scale *= distance / 10;
	}
	
	matrixStack.scale(-scale, -scale, scale);
	
	Matrix4f matrix4f = matrixStack.peek().getModel();
	float g = WurstClient.MC.options.getTextBackgroundOpacity(0.25F);
	int k = (int)(g * 255.0F) << 24;
	
	TextRenderer textRenderer = this.getFontRenderer();
	float h = -textRenderer.getWidth(text) / 2;
	
	textRenderer.draw(text, h, j, 553648127, false, matrix4f,
		vertexConsumerProvider, bl, k, i);
	
	if(bl)
		textRenderer.draw(text, h, j, -1, false, matrix4f,
			vertexConsumerProvider, false, 0, i);
	
	matrixStack.pop();
}
 
Example 20
Source File: SeaponyModel.java    From MineLittlePony with MIT License 4 votes vote down vote up
@Override
public void transform(BodyPart part, MatrixStack stack) {
    stack.translate(0, 0.6F, 0);
    super.transform(part, stack);
}