Java Code Examples for com.mojang.blaze3d.matrix.MatrixStack#push()
The following examples show how to use
com.mojang.blaze3d.matrix.MatrixStack#push() .
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: BlockOverlayRender.java From MiningGadgets with MIT License | 5 votes |
public static void render(RenderWorldLastEvent event, ItemStack item) { final Minecraft mc = Minecraft.getInstance(); IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource(); int range = MiningProperties.getBeamRange(item); BlockRayTraceResult lookingAt = VectorHelper.getLookingAt(mc.player, RayTraceContext.FluidMode.NONE, range); if (mc.world.getBlockState(VectorHelper.getLookingAt(mc.player, item, range).getPos()) == Blocks.AIR.getDefaultState()) { return; } List<BlockPos> coords = MiningCollect.collect(mc.player, lookingAt, mc.world, MiningProperties.getRange(item)); Vec3d view = mc.gameRenderer.getActiveRenderInfo().getProjectedView(); MatrixStack matrix = event.getMatrixStack(); matrix.push(); matrix.translate(-view.getX(), -view.getY(), -view.getZ()); IVertexBuilder builder; builder = buffer.getBuffer(MyRenderType.BlockOverlay); coords.forEach(e -> { if (mc.world.getBlockState(e).getBlock() != ModBlocks.RENDER_BLOCK.get()) { matrix.push(); matrix.translate(e.getX(), e.getY(), e.getZ()); matrix.translate(-0.005f, -0.005f, -0.005f); matrix.scale(1.01f, 1.01f, 1.01f); matrix.rotate(Vector3f.YP.rotationDegrees(-90.0F)); Matrix4f positionMatrix = matrix.getLast().getMatrix(); BlockOverlayRender.render(positionMatrix, builder, e, Color.GREEN); matrix.pop(); } }); matrix.pop(); RenderSystem.disableDepthTest(); buffer.finish(MyRenderType.BlockOverlay); }
Example 2
Source File: RenderTileEnderChest.java From EnderStorage with MIT License | 5 votes |
public static void renderChest(CCRenderState ccrs, MatrixStack mStack, IRenderTypeBuffer getter, int rotation, double yToCamera, Frequency freq, float lidAngle, int pearlOffset) { Matrix4 mat = new Matrix4(mStack); if (lidAngle != 0) {//Micro optimization, lid closed, dont render starfield. renderEndPortal.render(mat, getter, yToCamera); } ccrs.reset(); mStack.push(); mStack.translate(0, 1.0, 1.0); mStack.scale(1.0F, -1.0F, -1.0F); mStack.translate(0.5, 0.5, 0.5); mStack.rotate(new Quaternion(0, rotation * 90, 0, true)); mStack.translate(-0.5, -0.5, -0.5); model.chestLid.rotateAngleX = lidAngle; model.render(mStack, getter.getBuffer(chestType), ccrs.brightness, ccrs.overlay, freq.hasOwner()); mStack.pop(); //Buttons ccrs.bind(buttonType, getter); EnumColour[] colours = freq.toArray(); for (int i = 0; i < 3; i++) { CCModel button = ButtonModelLibrary.button.copy(); button.apply(BlockEnderChest.buttonT[i]); button.apply(new Translation(0.5, 0, 0.5)); button.apply(new Rotation(lidAngle, 1, 0, 0).at(new Vector3(0, 9D / 16D, 1 / 16D))); button.apply(new Rotation((-90 * (rotation)) * MathHelper.torad, Vector3.Y_POS).at(new Vector3(0.5, 0, 0.5))); button.render(ccrs, mat, new UVTranslation(0.25 * (colours[i].getWoolMeta() % 4), 0.25 * (colours[i].getWoolMeta() / 4))); } mat.translate(0.5, 0, 0.5); //Pearl if (lidAngle != 0) {//Micro optimization, lid closed, dont render pearl. double time = ClientUtils.getRenderTime() + pearlOffset; Matrix4 pearlMat = RenderUtils.getMatrix(mat.copy(), new Vector3(0, 0.2 + lidAngle * -0.5 + RenderUtils.getPearlBob(time), 0), new Rotation(time / 3, new Vector3(0, 1, 0)), 0.04); ccrs.brightness = 15728880; ccrs.bind(pearlType, getter); CCModelLibrary.icosahedron4.render(ccrs, pearlMat); } ccrs.reset(); }
Example 3
Source File: CCRenderItem.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void renderItem(ItemStack stack, ItemCameraTransforms.TransformType transformType, boolean leftHand, MatrixStack mStack, IRenderTypeBuffer getter, int packedLight, int packedOverlay, IBakedModel modelIn) { if (modelIn instanceof IItemRenderer) { mStack.push(); IBakedModel handled = ForgeHooksClient.handleCameraTransforms(mStack, modelIn, transformType, leftHand); mStack.translate(-0.5D, -0.5D, -0.5D); //If anyone doesnt return an IItemRenderer from here, your doing it wrong. ((IItemRenderer) handled).renderItem(stack, transformType, mStack, getter, packedLight, packedOverlay); mStack.pop(); } super.renderItem(stack, transformType, leftHand, mStack, getter, packedLight, packedOverlay, modelIn); }
Example 4
Source File: ChoppingBlockRenderer.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void render(ChoppingBlockTileEntity te, float partialTicks, MatrixStack matrixStack, IRenderTypeBuffer buffer, int p_225616_5_, int p_225616_6_) { BlockState state = te.getWorld().getBlockState(te.getPos()); if (!(state.getBlock() instanceof ChoppingBlock)) return; //if (destroyStage < 0) { matrixStack.push(); ItemRenderer itemRenderer = mc.getItemRenderer(); LazyOptional<IItemHandler> linv = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY); linv.ifPresent((inv) -> { ItemStack stack = inv.getStackInSlot(0); if (stack.getCount() > 0) { matrixStack.push(); matrixStack.translate(0.5, 0.5, 0.5); matrixStack.translate(0, -4.5 / 16.0f, 0); matrixStack.scale(2, 2, 2); IBakedModel ibakedmodel = itemRenderer.getItemModelWithOverrides(stack, te.getWorld(), (LivingEntity) null); itemRenderer.renderItem(stack, ItemCameraTransforms.TransformType.GROUND, true, matrixStack, buffer, p_225616_5_, p_225616_6_, ibakedmodel); /*int breakStage = te.getBreakStage(); if (breakStage >= 0) { renderItem(stack, ItemCameraTransforms.TransformType.GROUND, breakStage); }*/ matrixStack.pop(); } }); matrixStack.pop(); } }
Example 5
Source File: RenderMiningLaser2.java From MiningGadgets with MIT License | 4 votes |
private static void drawLasers(RenderWorldLastEvent event, Vec3d from, RayTraceResult trace, double xOffset, double yOffset, double zOffset, float r, float g, float b, float thickness, PlayerEntity player, float ticks, float speedModifier) { Hand activeHand; if (player.getHeldItemMainhand().getItem() instanceof MiningGadget) { activeHand = Hand.MAIN_HAND; } else if (player.getHeldItemOffhand().getItem() instanceof MiningGadget) { activeHand = Hand.OFF_HAND; } else { return; } IVertexBuilder builder; ItemStack stack = player.getHeldItem(activeHand); double distance = from.subtract(trace.getHitVec()).length(); long gameTime = player.world.getGameTime(); double v = gameTime * speedModifier; float additiveThickness = (thickness * 3.5f) * calculateLaserFlickerModifier(gameTime); float beam2r = MiningProperties.getColor(stack, MiningProperties.COLOR_RED_INNER) / 255f; float beam2g = MiningProperties.getColor(stack, MiningProperties.COLOR_GREEN_INNER) / 255f; float beam2b =MiningProperties.getColor(stack, MiningProperties.COLOR_BLUE_INNER) / 255f; Vec3d view = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView(); IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource(); MatrixStack matrix = event.getMatrixStack(); matrix.push(); matrix.translate(-view.getX(), -view.getY(), -view.getZ()); matrix.translate(from.x, from.y, from.z); matrix.rotate(Vector3f.YP.rotationDegrees(MathHelper.lerp(ticks, -player.rotationYaw, -player.prevRotationYaw))); matrix.rotate(Vector3f.XP.rotationDegrees(MathHelper.lerp(ticks, player.rotationPitch, player.prevRotationPitch))); MatrixStack.Entry matrixstack$entry = matrix.getLast(); Matrix3f matrixNormal = matrixstack$entry.getNormal(); Matrix4f positionMatrix = matrixstack$entry.getMatrix(); //additive laser beam builder = buffer.getBuffer(MyRenderType.LASER_MAIN_ADDITIVE); drawBeam(xOffset, yOffset, zOffset, builder, positionMatrix, matrixNormal, additiveThickness, activeHand, distance, 0.5, 1, ticks, r,g,b,0.7f); //main laser, colored part builder = buffer.getBuffer(MyRenderType.LASER_MAIN_BEAM); drawBeam(xOffset, yOffset, zOffset, builder, positionMatrix, matrixNormal, thickness, activeHand, distance, v, v + distance * 1.5, ticks, r,g,b,1f); //core builder = buffer.getBuffer(MyRenderType.LASER_MAIN_CORE); drawBeam(xOffset, yOffset, zOffset, builder, positionMatrix, matrixNormal, thickness/2, activeHand, distance, v, v + distance * 1.5, ticks, beam2r,beam2g,beam2b,1f); matrix.pop(); RenderSystem.disableDepthTest(); buffer.finish(); }
Example 6
Source File: DryingRackBakedModel.java From Survivalist with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Nonnull @Override public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData) { List<BakedQuad> quads = Lists.newArrayList(); RenderType renderLayer = MinecraftForgeClient.getRenderLayer(); if (renderLayer == RenderType.getSolid()) { quads.addAll(rackBakedModel.getQuads(state, side, rand)); } else if (renderLayer == RenderType.getCutout() && side == null) { ItemRenderer renderItem = Minecraft.getInstance().getItemRenderer(); World world = Minecraft.getInstance().world; DryingRackItemsStateData items = extraData.getData(DryingRackTileEntity.CONTAINED_ITEMS_DATA); for (int i = 0; i < 4; i++) { ItemStack stack = items.stacks[i]; if (stack.isEmpty()) continue; MatrixStack matrixStack = new MatrixStack(); matrixStack.push(); // pushMatrix TransformationMatrix ct = itemTransforms[i]; matrixStack.getLast().getMatrix().mul(ct.getMatrix()); // current().getPositionMatrix().multiply(getPositionMatrix) matrixStack.getLast().getNormal().mul(ct.getNormalMatrix()); // current().getNormalMatrix().multiply IBakedModel model = renderItem.getItemModelWithOverrides(stack, world, null); if (stack.getItem() == Items.TRIDENT) { model = Minecraft.getInstance().getItemRenderer().getItemModelMesher().getModelManager().getModel(new ModelResourceLocation("minecraft:trident#inventory")); } model = model.handlePerspective(ItemCameraTransforms.TransformType.FIXED, matrixStack); if (!model.isBuiltInRenderer()) { @SuppressWarnings("unchecked") Map<Pair<IBakedModel, TransformationMatrix>, List<BakedQuad>> cache = caches.get(i); Matrix4f positionTransform = matrixStack.getLast().getMatrix(); // current() // getPositionMatrix TransformationMatrix transformMatrix = new TransformationMatrix(positionTransform); Pair<IBakedModel, TransformationMatrix> pair = Pair.of(model, transformMatrix); List<BakedQuad> cachedQuads = cache.get(pair); if (cachedQuads == null) { cachedQuads = Lists.newArrayList(); for (Direction face : faces) { List<BakedQuad> inQuads = model.getQuads(null, face, rand); List<BakedQuad> outQuads = new QuadTransformer(transformMatrix).processMany(inQuads); cachedQuads.addAll(outQuads); } cache.put(pair, cachedQuads); } quads.addAll(cachedQuads); } } } return quads; }
Example 7
Source File: ICCBlockRenderer.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 3 votes |
/** * Called when vanilla is rendering breaking texture over your block. * Usually just render out your normal quads. * * @param state Your state. * @param pos Position. * @param world World. * @param mStack The {@link MatrixStack}. * @param builder The {@link IVertexBuilder} to add quads to. * @param data Any ModelData. */ default void renderBreaking(BlockState state, BlockPos pos, ILightReader world, MatrixStack mStack, IVertexBuilder builder, IModelData data) { CCRenderState ccrs = CCRenderState.instance(); ccrs.overlay = OverlayTexture.NO_OVERLAY; ccrs.brightness = WorldRenderer.getPackedLightmapCoords(world, state, pos); mStack.push(); renderBlock(state, pos, world, mStack, builder, new Random(), data); mStack.pop(); }