net.minecraft.client.util.math.Vector3f Java Examples

The following examples show how to use net.minecraft.client.util.math.Vector3f. 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: PlayerPonyRenderer.java    From MineLittlePony with MIT License 6 votes vote down vote up
@Override
public void render(AbstractClientPlayerEntity entity, float entityYaw, float tickDelta, MatrixStack stack, VertexConsumerProvider renderContext, int lightUv) {
    shadowRadius = manager.getShadowScale();
    super.render(entity, entityYaw, tickDelta, stack, renderContext, lightUv);
    DebugBoundingBoxRenderer.render(manager.getPony(entity), this, entity, stack, renderContext, tickDelta);

    // Translate the shadow position after everything is done
    // (shadows are drawn after us)
    if (!entity.hasVehicle() && !entity.isSleeping()) {
        float yaw = MathHelper.lerpAngleDegrees(tickDelta, entity.prevBodyYaw, entity.bodyYaw);
        float l = entity.getWidth() / 2 * manager.getPony(entity).getMetadata().getSize().getScaleFactor();

        stack.multiply(Vector3f.NEGATIVE_Y.getDegreesQuaternion(yaw));
        stack.translate(0, 0, -l);
    }
}
 
Example #2
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 #3
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 #4
Source File: PassengerFeature.java    From MineLittlePony with MIT License 6 votes vote down vote up
private void renderShoulderParrot(MatrixStack stack, VertexConsumerProvider renderContext, int lightUv, T entity, float limbDistance, float limbAngle, float headYaw, float headPitch, boolean left) {

        CompoundTag riderTag = left ? entity.getShoulderEntityLeft() : entity.getShoulderEntityRight();

        EntityType.get(riderTag.getString("id")).filter(p -> p == EntityType.PARROT).ifPresent((entityType) -> {
           stack.push();

           getContextModel().transform(BodyPart.BODY, stack);

           stack.translate(left ? 0.25 : -0.25, entity.isInSneakingPose() ? -0.5 : -0.25, 0.35);
           stack.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(left ? -5 : 5));

           VertexConsumer vertexConsumer = renderContext.getBuffer(model.getLayer(ParrotEntityRenderer.TEXTURES[riderTag.getInt("Variant")]));
           model.poseOnShoulder(stack, vertexConsumer, lightUv, OverlayTexture.DEFAULT_UV, limbDistance, limbAngle, headYaw, headPitch, entity.age);
           stack.pop();
        });
    }
 
Example #5
Source File: HeldItemFeature.java    From MineLittlePony with MIT License 6 votes vote down vote up
private void renderHeldItem(T entity, ItemStack drop, ModelTransformation.Mode transform, Arm arm, MatrixStack stack, VertexConsumerProvider renderContext, int lightUv) {
    if (!drop.isEmpty()) {
        stack.push();
        renderArm(arm, stack);

        if (getContextModel().getAttributes().isCrouching) {
            stack.translate(0, 0.2F, 0);
        }

        float left = arm == Arm.LEFT ? 1 : -1;

        if (entity.hasVehicle()) {
            stack.translate(left / 10, -0.2F, -0.5F);
        }

        stack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(-90));
        stack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(left * 180));
        stack.translate(left * -0.2F, 0, 0);

        preItemRender(entity, drop, transform, arm, stack);
        MinecraftClient.getInstance().getItemRenderer().renderItem(entity, drop, transform, arm == Arm.LEFT, stack, renderContext, entity.world, lightUv, OverlayTexture.DEFAULT_UV);
        postItemRender(entity, drop, transform, arm, stack, renderContext);

        stack.pop();
    }
}
 
Example #6
Source File: PostureFlight.java    From MineLittlePony with MIT License 5 votes vote down vote up
@Override
public void transform(IModel model, PlayerEntity player, MatrixStack stack, double motionX, double motionY, double motionZ, float yaw, float ticks) {
    model.getAttributes().motionPitch = (float) calculateIncline(player, motionX, motionY, motionZ);

    float roll = (float)calculateRoll(player, motionX,  motionY, motionZ);

    roll = model.getMetadata().getInterpolator(player.getUuid()).interpolate("pegasusRoll", roll, 10);

    stack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(model.getAttributes().motionPitch));
    stack.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(roll));
}
 
Example #7
Source File: AbstractPonyModel.java    From MineLittlePony with MIT License 5 votes vote down vote up
@Override
public void transform(BodyPart part, MatrixStack stack) {
    if (attributes.isSleeping) {
        stack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(90));
        stack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(180));
    }

    if (part == BodyPart.HEAD) {
       stack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(attributes.motionPitch));
    }

    PonyTransformation.forSize(getSize()).transform(this, part, stack);
}
 
Example #8
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 #9
Source File: SkullFeature.java    From MineLittlePony with MIT License 5 votes vote down vote up
private void renderBlock(MatrixStack stack, VertexConsumerProvider renderContext, T entity, ItemStack itemstack, int lightUv) {
    stack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(180));
    stack.scale(0.625F, -0.625F, -0.625F);
    stack.translate(0, 0.6F, -0.21F);

    MinecraftClient.getInstance().getHeldItemRenderer().renderItem(entity, itemstack, ModelTransformation.Mode.HEAD, false, stack, renderContext, lightUv);
}
 
Example #10
Source File: CapeFeature.java    From MineLittlePony with MIT License 5 votes vote down vote up
@Override
public void render(MatrixStack stack, VertexConsumerProvider renderContext, int lightUv, AbstractClientPlayerEntity player, float limbDistance, float limbAngle, float tickDelta, float age, float headYaw, float headPitch) {
    M model = getContextModel();

    if (player.hasSkinTexture() && !player.isInvisible()
            && player.isPartVisible(PlayerModelPart.CAPE) && player.getCapeTexture() != null
            && player.getEquippedStack(EquipmentSlot.CHEST).getItem() != Items.ELYTRA) {

        stack.push();

        model.transform(BodyPart.BODY, stack);
        stack.translate(0, 0.24F, 0);
        model.getBodyPart(BodyPart.BODY).rotate(stack);

        double capeX = MathHelper.lerp(tickDelta, player.capeX, player.prevCapeX) - MathHelper.lerp(tickDelta, player.prevX, player.getX());
        double capeY = MathHelper.lerp(tickDelta, player.capeY, player.prevCapeY) - MathHelper.lerp(tickDelta, player.prevY, player.getY());
        double capeZ = MathHelper.lerp(tickDelta, player.capeZ, player.prevCapeZ) - MathHelper.lerp(tickDelta, player.prevZ, player.getZ());

        float motionYaw = player.prevBodyYaw + (player.bodyYaw - player.prevBodyYaw);

        double sin = MathHelper.sin(motionYaw * PI / 180);
        double cos = (-MathHelper.cos(motionYaw * PI / 180));

        float capeMotionY = (float) capeY * 10;

        if (capeMotionY < -6) capeMotionY = -6;
        if (capeMotionY > 32) capeMotionY = 32;

        float capeMotionX = (float) (capeX * sin + capeZ * cos) * 100;

        float diagMotion =  (float) (capeX * cos - capeZ * sin) * 100;

        if (capeMotionX < 0) capeMotionX = 0;

        float camera = MathHelper.lerp(tickDelta, player.prevStrideDistance, player.strideDistance);
        capeMotionY += MathHelper.sin(MathHelper.lerp(tickDelta, player.prevHorizontalSpeed, player.horizontalSpeed) * 6) * 32 * camera;

        stack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(2 + capeMotionX / 12 + capeMotionY));
        stack.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion( diagMotion / 2));
        stack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(-diagMotion / 2));
        stack.multiply(Vector3f.POSITIVE_Z.getDegreesQuaternion(180));
        stack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(90));

        VertexConsumer vertices = renderContext.getBuffer(RenderLayer.getEntitySolid(player.getCapeTexture()));
        model.renderCape(stack, vertices, lightUv, OverlayTexture.DEFAULT_UV);
        stack.pop();
    }
}
 
Example #11
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 #12
Source File: ConfigurableElectricMachineBlockEntityRenderer.java    From Galacticraft-Rewoven with MIT License 5 votes vote down vote up
private static List<ModelElement> generateCube() {
    Map<Direction, ModelElementFace> faces = new HashMap<>();
    for (Direction direction : Direction.values()) {
        faces.put(direction, new ModelElementFace(null, -1, direction.getName(), new ModelElementTexture(null, 0)));
    }
    return Collections.singletonList(new ModelElement(new Vector3f(0, 0, 0), new Vector3f(16, 16, 16), faces, null, true));
}
 
Example #13
Source File: BlockWrapper.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static ActionResult statisOnUse(org.sandboxpowered.sandbox.api.state.BlockState blockState_1, org.sandboxpowered.sandbox.api.world.World world_1, Position blockPos_1, PlayerEntity playerEntity_1, Hand hand_1, BlockHitResult blockHitResult_1, Block block) {
    InteractionResult result = block.onBlockUsed(
            world_1,
            blockPos_1,
            blockState_1,
            playerEntity_1,
            hand_1 == Hand.MAIN_HAND ? org.sandboxpowered.sandbox.api.entity.player.Hand.MAIN_HAND : org.sandboxpowered.sandbox.api.entity.player.Hand.OFF_HAND,
            WrappingUtil.convert(blockHitResult_1.getSide()),
            (Vec3f) (Object) new Vector3f(blockHitResult_1.getPos())
    );
    return WrappingUtil.convert(result);
}
 
Example #14
Source File: HallowedCactusEntityRenderer.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public void render(RestlessCactusEntity entity, float yaw, float tickDelta, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int light) {
	BlockRenderManager manager = MinecraftClient.getInstance().getBlockRenderManager();
	BlockState state = HallowedBlocks.RESTLESS_CACTUS.getDefaultState();
	renderManager.textureManager.bindTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEX);
	matrixStack.push();
	matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(-yaw));
	matrixStack.translate(-0.5f, 0.0f, -0.5f);
	
	for (int i = 0; i < entity.getCactusHeight(); i++) {
		manager.renderBlockAsEntity(state, matrixStack, vertexConsumerProvider, light, OverlayTexture.DEFAULT_UV);
		matrixStack.translate(0.0F, 1.0F, 0.0F);
	}
	matrixStack.pop();
}
 
Example #15
Source File: InfusionPillarBlockEntityRenderer.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public void render(InfusionPillarBlockEntity pillar, float partialTicks, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j) {
	ItemRenderer itemRenderer = MinecraftClient.getInstance().getItemRenderer();
	
	if (!pillar.storedStack.isEmpty()) {
		matrixStack.push();
		matrixStack.translate(0.5, 1.25 + MathHelper.sin(rotation / 2) / 32, 0.5);
		matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(rotation * 2));
		matrixStack.scale(0.5f, 0.5f, 0.5f);
		itemRenderer.renderItem(pillar.storedStack, ModelTransformation.Mode.FIXED, i, j, matrixStack, vertexConsumerProvider);
		matrixStack.pop();
	}
	
	nanosA = System.nanoTime();
	if ((nanosA - nanosB) / 1000000 > 16) {
		nanosB = System.nanoTime();
		if (rotationMode) {
			rotation += 0.16;
			if (rotation >= 360) {
				rotationMode = !rotationMode;
			}
		} else {
			rotation += 0.16;
			if (rotation <= 0) {
				rotationMode = !rotationMode;
			}
		}
	}
	
}
 
Example #16
Source File: InfusionAltarBlockEntityRenderer.java    From the-hallow with MIT License 5 votes vote down vote up
@Override
public void render(InfusionAltarBlockEntity altar, float partialTicks, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j) {
	ItemRenderer itemRenderer = MinecraftClient.getInstance().getItemRenderer();
	
	if (!altar.storedStack.isEmpty()) {
		matrixStack.push();
		matrixStack.translate(0.5, 1.25 + MathHelper.sin(rotation / 2) / 32, 0.5);
		matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(rotation * 2));
		matrixStack.scale(0.5f, 0.5f, 0.5f);
		itemRenderer.renderItem(altar.storedStack, ModelTransformation.Mode.FIXED, i, j, matrixStack, vertexConsumerProvider);
		matrixStack.pop();
	}
	
	nanosA = System.nanoTime();
	if ((nanosA - nanosB) / 1000000 > 16) {
		nanosB = System.nanoTime();
		if (rotationMode) {
			rotation += 0.16;
			if (rotation >= 360) {
				rotationMode = !rotationMode;
			}
		} else {
			rotation += 0.16;
			if (rotation <= 0) {
				rotationMode = !rotationMode;
			}
		}
	}
	
}
 
Example #17
Source File: SkirtCostumeItem.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 #18
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 #19
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 #20
Source File: PostureElytra.java    From MineLittlePony with MIT License 4 votes vote down vote up
@Override
public void transform(IModel model, LivingEntity entity, MatrixStack stack, double motionX, double motionY, double motionZ, float yaw, float ticks) {
    stack.multiply(Vector3f.POSITIVE_X.getDegreesQuaternion(90));
    stack.translate(0, model.getAttributes().isCrouching ? 0.2F : -1, 0);
}