Пример #1
0
        public void drawSign(Camera camera)
        {
            TexturedBatch3D texturedBatch3D = primitivesRenderer3D.TexturedBatch(m_renderTarget, false, 0, DepthStencilState.None, RasterizerState.CullCounterClockwiseScissor, BlendState.AlphaBlend, SamplerState.PointWrap);

            foreach (KeyValuePair <Point3, int> item in pointlist)
            {
                renderPoint = item.Key;
                if (Vector3.DistanceSquared(new Vector3(renderPoint), camera.ViewPosition) > 400f)
                {
                    continue;                                                                                               //超出20f视野
                }
                ComponentSingleChest singleChest = subsystemBlockEntities.GetBlockEntity(renderPoint.X, renderPoint.Y, renderPoint.Z).Entity.FindComponent <ComponentSingleChest>(true);
                if (singleChest == null || singleChest.GetSlotCount(0) == 0)
                {
                    continue;
                }
                int       mvalue = subsystemTerrain.Terrain.GetCellValue(renderPoint.X, renderPoint.Y, renderPoint.Z);
                int       mpos   = ILibrary.GetDirection(mvalue);
                BlockMesh signSurfaceBlockMesh = MekiasmInit.faceMeshes.Array[ILibrary.normalpos[mpos]];
                float     s                 = LightingManager.LightIntensityByLightValue[Terrain.ExtractLight(mvalue)];
                Color     color             = new Color(s, s, s);
                Vector3   signSurfaceNormal = MekiasmInit.faceNormals.Array[ILibrary.normalface[ILibrary.normalpos[mpos]]];
                Vector3   vector            = new Vector3(renderPoint);
                float     num3              = Vector3.Dot(camera.ViewPosition - (vector + new Vector3(0.5f)), signSurfaceNormal);
                Vector3   v                 = MathUtils.Max(0.01f * num3, 0.005f) * signSurfaceNormal;
                int       indecies          = signSurfaceBlockMesh.Indices.Count / 3;
                for (int i = 0; i < indecies; i += 2)
                {
                    if (i >= indecies)
                    {
                        break;
                    }
                    BlockMeshVertex blockMeshVertex  = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3]];
                    BlockMeshVertex blockMeshVertex2 = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3 + 1]];
                    BlockMeshVertex blockMeshVertex3 = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3 + 2]];
                    Vector3         p  = blockMeshVertex.Position + vector + v;
                    Vector3         p2 = blockMeshVertex2.Position + vector + v;
                    Vector3         p3 = blockMeshVertex3.Position + vector + v;
                    Vector2         textureCoordinates  = ILibrary.getTexcoord(2);
                    Vector2         textureCoordinates2 = ILibrary.getTexcoord(3);
                    Vector2         textureCoordinates3 = ILibrary.getTexcoord(4);
                    texturedBatch3D.QueueTriangle(p, p2, p3, textureCoordinates, textureCoordinates2, textureCoordinates3, color);
                    BlockMeshVertex blockMeshVertex11 = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[++i * 3]];
                    BlockMeshVertex blockMeshVertex22 = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3 + 1]];
                    BlockMeshVertex blockMeshVertex33 = signSurfaceBlockMesh.Vertices.Array[signSurfaceBlockMesh.Indices.Array[i * 3 + 2]];
                    Vector3         p11 = blockMeshVertex11.Position + vector + v;
                    Vector3         p22 = blockMeshVertex22.Position + vector + v;
                    Vector3         p33 = blockMeshVertex33.Position + vector + v;
                    Vector2         textureCoordinates11 = ILibrary.getTexcoord(2);
                    Vector2         textureCoordinates22 = ILibrary.getTexcoord(4);
                    Vector2         textureCoordinates33 = ILibrary.getTexcoord(1);
                    texturedBatch3D.QueueTriangle(p11, p22, p33, textureCoordinates11, textureCoordinates22, textureCoordinates33, color);
                }
                Updated(singleChest.GetSlotValue(0), singleChest.GetSlotCount(0));
                primitivesRenderer3D.Flush(camera.ViewProjectionMatrix);
            }
        }
Пример #2
0
        public override void OnHitByProjectile(CellFace cellFace, WorldItem worldItem)
        {        //收集掉落物
            ++ll; if (ll >= 2)
            {
                ll = 0; return;
            }
            int value  = subsystemTerrain.Terrain.GetCellValueFast(cellFace.Point.X, cellFace.Point.Y, cellFace.Point.Z);
            int level  = ILibrary.getItemId(value);
            int maxcnt = (int)Math.Pow((double)2, (double)level) * 128;        //计算最大容量

            if (Terrain.ExtractContents(value) == HandledBlocks[0])
            {
                try {
                    ComponentBlockEntity componentBlockEntity = subsystemBlockEntities.GetBlockEntity(cellFace.X, cellFace.Y, cellFace.Z);
                    if (componentBlockEntity == null)
                    {
                        toast("没有找到Blockentity"); return;
                    }
                    ComponentSingleChest singleChestData = componentBlockEntity.Entity.FindComponent <ComponentSingleChest>(true);
                    if (singleChestData == null)
                    {
                        toast("没有找到componentchest"); return;
                    }
                    if (worldItem.ToRemove)
                    {
                        return;
                    }
                    Pickable pickable = worldItem as Pickable;
                    int      num      = pickable?.Count ?? 1;
                    int      num2     = saveInventory(singleChestData, worldItem.Value, num, maxcnt);
                    if (num2 < num)
                    {
                        subsystemAudio.PlaySound("Audio/PickableCollected", 1f, 0f, worldItem.Position, 3f, autoDelay: true);
                    }
                    if (num2 <= 0)
                    {
                        worldItem.ToRemove = true;
                    }
                    else if (pickable != null)
                    {
                        pickable.Count = num2;
                    }
                }
                catch (Exception e) {
                    toast(e.ToString());
                }
            }
        }
Пример #3
0
        public override bool OnInteract(TerrainRaycastResult raycastResult, ComponentMiner componentMiner)
        {        //记录point
            ++ll; if (ll >= 2)
            {
                ll = 0; return(true);
            }
            componentPlayer = componentMiner.ComponentPlayer;
            ComponentBlockEntity componentBlockEntity = subsystemBlockEntities.GetBlockEntity(raycastResult.CellFace.X, raycastResult.CellFace.Y, raycastResult.CellFace.Z);

            if (componentBlockEntity == null)
            {
                toast("没有找到Blockentity"); return(false);
            }
            ComponentSingleChest singleChestData = componentBlockEntity.Entity.FindComponent <ComponentSingleChest>(true);

            singleChestData.Droptems(new Vector3(raycastResult.CellFace.X, raycastResult.CellFace.Y, raycastResult.CellFace.Z) + new Vector3(1f, 1f, 1f), 1);
            return(true);
        }