public override bool DoPlaceBlock(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ItemStack byItemStack)
        {
            bool ok = base.DoPlaceBlock(world, byPlayer, blockSel, byItemStack);

            if (!ok)
            {
                return(false);
            }

            BELantern be = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BELantern;

            if (be != null)
            {
                string material = byItemStack.Attributes.GetString("material");
                string lining   = byItemStack.Attributes.GetString("lining");
                string glass    = byItemStack.Attributes.GetString("glass");
                be.DidPlace(material, lining, glass);

                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        = byPlayer.Entity.Pos.Z - (targetPos.Z + blockSel.HitPosition.Z);
                float    angleHor  = (float)Math.Atan2(dx, dz);

                float deg22dot5rad = GameMath.PIHALF / 4;
                float roundRad     = ((int)Math.Round(angleHor / deg22dot5rad)) * deg22dot5rad;
                be.MeshAngle = roundRad;
            }

            return(true);
        }
        public override byte[] GetLightHsv(IBlockAccessor blockAccessor, BlockPos pos, ItemStack stack = null)
        {
            if (pos != null)
            {
                BELantern be = blockAccessor.GetBlockEntity(pos) as BELantern;
                if (be != null)
                {
                    return(be.GetLightHsv());
                }
            }

            if (stack != null)
            {
                string lining   = stack.Attributes.GetString("lining");
                string material = stack.Attributes.GetString("material");

                int v = this.LightHsv[2] + (lining != "plain" ? 2 : 0);

                byte[] lightHsv = new byte[] { this.LightHsv[0], this.LightHsv[1], (byte)v };
                BELantern.setLightColor(this.LightHsv, lightHsv, stack.Attributes.GetString("glass"));

                return(lightHsv);
            }

            return(base.GetLightHsv(blockAccessor, pos, stack));
        }
Beispiel #3
0
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            if (!byPlayer.Entity.Controls.Sneak)
            {
                BELantern bel = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BELantern;
                bel.Interact(byPlayer);
                return(true);
            }

            return(base.OnBlockInteractStart(world, byPlayer, blockSel));
        }
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            if (!byPlayer.Entity.Controls.Sneak)
            {
                BELantern bel = world.BlockAccessor.GetBlockEntity(blockSel.Position) as BELantern;
                if (bel.Interact(byPlayer))
                {
                    return(true);
                }
                // if Interact returned false, the player had an empty slot so revert to base: right-click pickup
            }

            return(base.OnBlockInteractStart(world, byPlayer, blockSel));
        }
        public override int GetRandomColor(ICoreClientAPI capi, BlockPos pos, BlockFacing facing)
        {
            BELantern be = capi.World.BlockAccessor.GetBlockEntity(pos) as BELantern;

            if (be != null)
            {
                CompositeTexture tex = null;
                if (Textures.TryGetValue(be.material, out tex))
                {
                    return(capi.BlockTextureAtlas.GetRandomColor(tex.Baked.TextureSubId));
                }
            }

            return(base.GetRandomColor(capi, pos, facing));
        }
Beispiel #6
0
        public override void DoPlaceBlock(IWorldAccessor world, BlockPos pos, BlockFacing onBlockFace, ItemStack byItemStack)
        {
            base.DoPlaceBlock(world, pos, onBlockFace, byItemStack);

            //string sdf = this.Code.Path;

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

            if (be != null)
            {
                string material = byItemStack.Attributes.GetString("material");
                string lining   = byItemStack.Attributes.GetString("lining");
                be.DidPlace(material, lining);
            }
        }
Beispiel #7
0
        public override ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos)
        {
            ItemStack stack = base.OnPickBlock(world, pos);

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

            if (be != null)
            {
                stack.Attributes.SetString("material", be.material);
                stack.Attributes.SetString("lining", be.lining);
            }
            else
            {
                stack.Attributes.SetString("material", "copper");
                stack.Attributes.SetString("lining", "plain");
            }

            return(stack);
        }