Esempio n. 1
0
        public void DetermineBuildStages()
        {
            BlockPitkiln blockpk = this.Block as BlockPitkiln;
            bool         found   = false;

            foreach (var val in blockpk.BuildStagesByBlock)
            {
                if (!inventory[0].Empty && WildcardUtil.Match(new AssetLocation(val.Key), inventory[0].Itemstack.Collectible.Code))
                {
                    buildStages = val.Value;
                    shape       = blockpk.ShapesByBlock[val.Key];
                    found       = true;
                    break;
                }
            }
            if (!found)
            {
                if (blockpk.BuildStagesByBlock.TryGetValue("*", out buildStages))
                {
                    shape = blockpk.ShapesByBlock["*"];
                }
            }

            updateSelectiveElements();
        }
Esempio n. 2
0
        public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak)
            {
                return;
            }

            IWorldAccessor world        = byEntity.World;
            Block          firepitBlock = world.GetBlock(new AssetLocation("firepit-construct1"));

            if (firepitBlock == null)
            {
                return;
            }


            BlockPos onPos = blockSel.DidOffset ? blockSel.Position : blockSel.Position.AddCopy(blockSel.Face);

            IPlayer byPlayer = byEntity.World.PlayerByUid((byEntity as EntityPlayer)?.PlayerUID);

            if (!byEntity.World.Claims.TryAccess(byPlayer, onPos, EnumBlockAccessFlags.BuildOrBreak))
            {
                return;
            }



            Block block      = world.BlockAccessor.GetBlock(onPos.DownCopy());
            Block aimedBlock = world.BlockAccessor.GetBlock(blockSel.Position);

            if (aimedBlock is BlockGroundStorage)
            {
                if (!(aimedBlock is BlockPitkiln))
                {
                    BlockPitkiln blockpk = world.GetBlock(new AssetLocation("pitkiln")) as BlockPitkiln;
                    if (blockpk.TryCreateKiln(world, byPlayer, blockSel.Position))
                    {
                        handHandling = EnumHandHandling.PreventDefault;
                    }
                }
            }
            else
            {
                string useless = "";

                if (!block.CanAttachBlockAt(byEntity.World.BlockAccessor, firepitBlock, onPos.DownCopy(), BlockFacing.UP))
                {
                    return;
                }
                if (!firepitBlock.CanPlaceBlock(world, byPlayer, new BlockSelection()
                {
                    Position = onPos, Face = BlockFacing.UP
                }, ref useless))
                {
                    return;
                }

                world.BlockAccessor.SetBlock(firepitBlock.BlockId, onPos);

                if (firepitBlock.Sounds != null)
                {
                    world.PlaySoundAt(firepitBlock.Sounds.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer);
                }

                itemslot.Itemstack.StackSize--;
                handHandling = EnumHandHandling.PreventDefaultAction;
            }
        }