Ejemplo n.º 1
0
        public override void GetDecal(IWorldAccessor world, BlockPos pos, ITexPositionSource decalTexSource, ref MeshData decalModelData, ref MeshData blockModelData)
        {
            BlockEntityIceBox be = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityIceBox;

            if (be != null)
            {
                ICoreClientAPI capi      = api as ICoreClientAPI;
                string         shapename = this.Attributes["shape"][be.type].AsString();
                if (shapename == null)
                {
                    base.GetDecal(world, pos, decalTexSource, ref decalModelData, ref blockModelData);
                    return;
                }

                blockModelData = GenMesh(capi, be.type, shapename);

                AssetLocation shapeloc = new AssetLocation(shapename).WithPathPrefix("shapes/");
                Shape         shape    = capi.Assets.TryGet(shapeloc + ".json")?.ToObject <Shape>();
                if (shape == null)
                {
                    shape = capi.Assets.TryGet(shapeloc + "1.json").ToObject <Shape>();
                }

                MeshData md;
                capi.Tesselator.TesselateShape("typedcontainer-decal", shape, out md, decalTexSource);
                decalModelData = md;

                decalModelData.Rotate(new Vec3f(0.5f, 0.5f, 0.5f), 0, be.MeshAngle, 0);

                return;
            }

            base.GetDecal(world, pos, decalTexSource, ref decalModelData, ref blockModelData);
        }
Ejemplo n.º 2
0
        public override Cuboidf[] GetSelectionBoxes(IBlockAccessor blockAccessor, BlockPos pos)
        {
            BlockEntityIceBox bect = blockAccessor.GetBlockEntity(pos) as BlockEntityIceBox;

            if (bect?.collisionSelectionBoxes != null)
            {
                return(bect.collisionSelectionBoxes);
            }

            return(base.GetSelectionBoxes(blockAccessor, pos));
        }
Ejemplo n.º 3
0
        public string GetType(IBlockAccessor blockAccessor, BlockPos pos)
        {
            BlockEntityIceBox be = blockAccessor.GetBlockEntity(pos) as BlockEntityIceBox;

            if (be != null)
            {
                return(be.type);
            }

            return(defaultType);
        }
Ejemplo n.º 4
0
        public override int GetRandomColor(ICoreClientAPI capi, BlockPos pos, BlockFacing facing)
        {
            BlockEntityIceBox be = capi.World.BlockAccessor.GetBlockEntity(pos) as BlockEntityIceBox;

            if (be != null)
            {
                CompositeTexture tex = null;
                if (!Textures.TryGetValue(be.type + "-lid", out tex))
                {
                    Textures.TryGetValue(be.type + "-top", out tex);
                }
                return(capi.BlockTextureAtlas.GetRandomColor(tex?.Baked == null ? 0 : tex.Baked.TextureSubId));
            }

            return(base.GetRandomColor(capi, pos, facing));
        }
Ejemplo n.º 5
0
        public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos)
        {
            ItemStack stack = new ItemStack(world.GetBlock(CodeWithVariant("side", "east")));

            BlockEntityIceBox be = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityIceBox;

            if (be != null)
            {
                stack.Attributes.SetString("type", be.type);
            }
            else
            {
                stack.Attributes.SetString("type", defaultType);
            }

            return(stack);
        }
Ejemplo n.º 6
0
        public override bool DoPlaceBlock(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ItemStack byItemStack)
        {
            bool val = base.DoPlaceBlock(world, byPlayer, blockSel, byItemStack);

            if (val)
            {
                BlockEntityIceBox bect = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BlockEntityIceBox;
                if (bect != null)
                {
                    BlockPos targetPos = blockSel.DidOffset ? blockSel.Position.AddCopy(blockSel.Face.Opposite) : blockSel.Position;
                    double   dx        = byPlayer.Entity.Pos.X - (targetPos.X + blockSel.HitPosition.X);
                    double   dz        = (float)byPlayer.Entity.Pos.Z - (targetPos.Z + blockSel.HitPosition.Z);
                    float    angleHor  = (float)Math.Atan2(dx, dz);


                    string type = bect.type;
                    string rotatatableInterval = Attributes?["rotatatableInterval"][type]?.AsString("22.5deg") ?? "22.5deg";

                    if (rotatatableInterval == "22.5degnot45deg")
                    {
                        float rounded90degRad = ((int)Math.Round(angleHor / GameMath.PIHALF)) * GameMath.PIHALF;
                        float deg45rad        = GameMath.PIHALF / 4;


                        if (Math.Abs(angleHor - rounded90degRad) >= deg45rad)
                        {
                            bect.MeshAngle = rounded90degRad + 22.5f * GameMath.DEG2RAD * Math.Sign(angleHor - rounded90degRad);
                        }
                        else
                        {
                            bect.MeshAngle = rounded90degRad;
                        }
                    }
                    if (rotatatableInterval == "22.5deg")
                    {
                        float deg22dot5rad = GameMath.PIHALF / 4;
                        float roundRad     = ((int)Math.Round(angleHor / deg22dot5rad)) * deg22dot5rad;
                        bect.MeshAngle = roundRad;
                    }
                }
            }

            return(val);
        }