private ItemRenderInfo GetRenderInfo(CarriedBlock carried) { // Alternative: Cache API.TesselatorManager.GetDefaultBlockMesh manually. var renderInfo = API.Render.GetItemStackRenderInfo(carried.ItemStack, EnumItemRenderTarget.Ground); var behavior = carried.Behavior; renderInfo.Transform = behavior.Slots[carried.Slot]?.Transform ?? behavior.DefaultTransform; return(renderInfo); }
private ItemRenderInfo GetRenderInfo(CarriedBlock carried) { // Alternative: Cache API.TesselatorManager.GetDefaultBlockMesh manually. var renderInfo = API.Render.GetItemStackRenderInfo( carried.ItemStack, EnumItemRenderTarget.Ground); renderInfo.Transform = carried.Block.GetBehaviorOrDefault( BlockBehaviorCarryable.DEFAULT).Transform; return(renderInfo); }
private void UpgradeFrom034(Entity entity) { var oldStackAttributeID = $"{ CarrySystem.MOD_ID }:CarriedBlock/Stack"; var oldDataAttributeID = $"{ CarrySystem.MOD_ID }:CarriedBlock/Data"; var oldItemStack = entity.WatchedAttributes.GetItemstack(oldStackAttributeID); if (oldItemStack == null) { return; } oldItemStack.ResolveBlockOrItem(entity.World); var oldBlockEntityData = entity.Attributes.GetTreeAttribute(oldDataAttributeID); entity.WatchedAttributes.RemoveAttribute(oldStackAttributeID); entity.Attributes.RemoveAttribute(oldDataAttributeID); CarriedBlock.Set(entity, CarrySlot.Back, oldItemStack, oldBlockEntityData); }
private void UpgradeFrom032(Entity entity) { var oldAttributeID = $"{ CarrySystem.MOD_ID }:CarriedBlock"; var oldBlockCode = entity.WatchedAttributes.GetString(oldAttributeID); if (oldBlockCode == null) { return; } var oldBlock = entity.World.GetBlock(new AssetLocation(oldBlockCode)); if (oldBlock == null) { return; } var oldBlockEntityData = entity.Attributes.GetTreeAttribute(oldAttributeID); entity.WatchedAttributes.RemoveAttribute(oldAttributeID); entity.Attributes.RemoveAttribute(oldAttributeID); CarriedBlock.Set(entity, CarrySlot.Back, new ItemStack(oldBlock), oldBlockEntityData); }
/// <summary> Renders the specified carried block on the specified entity. </summary> private void RenderCarried(EntityAgent entity, CarriedBlock carried, float deltaTime, bool isLocalPlayer, bool isFirstPerson, bool isImmersiveFirstPerson, bool isShadowPass, EntityShapeRenderer renderer, IAnimator animator) { var inHands = (carried.Slot == CarrySlot.Hands); if (!inHands && isFirstPerson && !isShadowPass) { return; // Only Hands slot is rendered in first person. } var viewMat = Array.ConvertAll(API.Render.CameraMatrixOrigin, i => (float)i); var renderSettings = _renderSettings[carried.Slot]; var renderInfo = GetRenderInfo(carried); float[] modelMat; if (inHands && isFirstPerson && !isImmersiveFirstPerson && !isShadowPass) { modelMat = GetFirstPersonHandsMatrix(entity, viewMat, deltaTime); } else { var attachPointAndPose = animator.GetAttachmentPointPose(renderSettings.AttachmentPoint); if (attachPointAndPose == null) { return; // Couldn't find attachment point. } modelMat = GetAttachmentPointMatrix(renderer, attachPointAndPose); // If in immersive first person, move the model down a bit so it's not too much "in your face". if (isImmersiveFirstPerson) { Mat4f.Translate(modelMat, modelMat, 0.0F, -0.12F, 0.0F); } } // Apply carried block's behavior transform. var t = renderInfo.Transform; Mat4f.Scale(modelMat, modelMat, t.ScaleXYZ.X, t.ScaleXYZ.Y, t.ScaleXYZ.Z); Mat4f.Translate(modelMat, modelMat, renderSettings.Offset.X, renderSettings.Offset.Y, renderSettings.Offset.Z); Mat4f.Translate(modelMat, modelMat, t.Origin.X, t.Origin.Y, t.Origin.Z); Mat4f.RotateX(modelMat, modelMat, t.Rotation.X * GameMath.DEG2RAD); Mat4f.RotateZ(modelMat, modelMat, t.Rotation.Z * GameMath.DEG2RAD); Mat4f.RotateY(modelMat, modelMat, t.Rotation.Y * GameMath.DEG2RAD); Mat4f.Translate(modelMat, modelMat, -t.Origin.X, -t.Origin.Y, -t.Origin.Z); Mat4f.Translate(modelMat, modelMat, t.Translation.X, t.Translation.Y, t.Translation.Z); if (isShadowPass) { var prog = API.Render.CurrentActiveShader; Mat4f.Mul(modelMat, API.Render.CurrentShadowProjectionMatrix, modelMat); prog.BindTexture2D("tex2d", renderInfo.TextureId, 0); prog.UniformMatrix("mvpMatrix", modelMat); prog.Uniform("origin", renderer.OriginPos); API.Render.RenderMesh(renderInfo.ModelRef); } else { var prog = API.Render.PreparedStandardShader((int)entity.Pos.X, (int)entity.Pos.Y, (int)entity.Pos.Z); prog.Tex2D = renderInfo.TextureId; prog.AlphaTest = 0.01f; prog.ViewMatrix = viewMat; prog.ModelMatrix = modelMat; prog.DontWarpVertices = 1; API.Render.RenderMesh(renderInfo.ModelRef); prog.Stop(); } }