public override bool CanAttachBlockAt(IBlockAccessor blockAccessor, Block block, BlockPos pos, BlockFacing blockFace, Cuboidi attachmentArea = null)
        {
            BlockEntityFirewoodPile be = blockAccessor.GetBlockEntity(pos) as BlockEntityFirewoodPile;

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

            return(base.CanAttachBlockAt(blockAccessor, block, pos, blockFace, attachmentArea));
        }
        public override bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel)
        {
            BlockEntity be = world.BlockAccessor.GetBlockEntity(blockSel.Position);

            if (be is BlockEntityFirewoodPile)
            {
                BlockEntityFirewoodPile pile = (BlockEntityFirewoodPile)be;
                return(pile.OnPlayerInteract(byPlayer));
            }

            return(false);
        }
        public bool Construct(ItemSlot slot, IWorldAccessor world, BlockPos pos, IPlayer player)
        {
            Block block = world.BlockAccessor.GetBlock(pos);

            if (!block.IsReplacableBy(this))
            {
                return(false);
            }
            Block belowBlock = world.BlockAccessor.GetBlock(pos.DownCopy());

            if (!belowBlock.CanAttachBlockAt(world.BlockAccessor, this, pos.DownCopy(), BlockFacing.UP) && (belowBlock != this || FillLevel(world.BlockAccessor, pos.DownCopy()) != 4))
            {
                return(false);
            }

            world.BlockAccessor.SetBlock(BlockId, pos);

            BlockEntity be = world.BlockAccessor.GetBlockEntity(pos);

            if (be is BlockEntityFirewoodPile)
            {
                BlockEntityFirewoodPile pile = (BlockEntityFirewoodPile)be;
                if (player == null || player.WorldData.CurrentGameMode != EnumGameMode.Creative)
                {
                    pile.inventory[0].Itemstack = (ItemStack)slot.TakeOut(player.Entity.Controls.Sprint ? pile.BulkTakeQuantity : pile.DefaultTakeQuantity);
                    slot.MarkDirty();
                }
                else
                {
                    pile.inventory[0].Itemstack           = (ItemStack)slot.Itemstack.Clone();
                    pile.inventory[0].Itemstack.StackSize = Math.Min(pile.inventory[0].Itemstack.StackSize, pile.MaxStackSize);
                }

                pile.MarkDirty();
                world.BlockAccessor.MarkBlockDirty(pos);
                world.PlaySoundAt(pile.soundLocation, pos.X, pos.Y, pos.Z, player, true);
            }

            return(true);
        }
예제 #4
0
        internal bool Construct(IItemSlot slot, IWorldAccessor world, BlockPos pos, IPlayer player)
        {
            Block block = world.BlockAccessor.GetBlock(pos);

            if (!block.IsReplacableBy(this))
            {
                return(false);
            }
            Block belowBlock = world.BlockAccessor.GetBlock(pos.DownCopy());

            if (!belowBlock.SideSolid[BlockFacing.UP.Index] && (belowBlock != this || FillLevel(world.BlockAccessor, pos.DownCopy()) != 4))
            {
                return(false);
            }

            world.BlockAccessor.SetBlock(BlockId, pos);

            BlockEntity be = world.BlockAccessor.GetBlockEntity(pos);

            if (be is BlockEntityFirewoodPile)
            {
                BlockEntityFirewoodPile pile = (BlockEntityFirewoodPile)be;
                if (player == null || player.WorldData.CurrentGameMode != EnumGameMode.Creative)
                {
                    pile.inventory.GetSlot(0).Itemstack = (ItemStack)slot.TakeOut(2);
                    slot.MarkDirty();
                }
                else
                {
                    pile.inventory.GetSlot(0).Itemstack = (ItemStack)slot.Itemstack.Clone();
                }

                pile.MarkDirty();
                world.BlockAccessor.MarkBlockDirty(pos);
                world.PlaySoundAt(new AssetLocation("sounds/block/planks"), pos.X, pos.Y, pos.Z, player, false);
            }

            return(true);
        }
예제 #5
0
        void ConvertPit()
        {
            Dictionary <BlockPos, Vec2i> quantityPerColumn = new Dictionary <BlockPos, Vec2i>();

            HashSet <BlockPos> visitedPositions = new HashSet <BlockPos>();
            Queue <BlockPos>   bfsQueue         = new Queue <BlockPos>();

            bfsQueue.Enqueue(pos);

            int maxHalfSize     = 6;
            int firewoodBlockId = api.World.GetBlock(new AssetLocation("firewoodpile")).BlockId;

            Vec2i curQuantityAndYPos = new Vec2i();

            while (bfsQueue.Count > 0)
            {
                BlockPos bpos = bfsQueue.Dequeue();

                BlockPos bposGround = bpos.Copy();
                bposGround.Y = 0;

                if (quantityPerColumn.TryGetValue(bposGround, out curQuantityAndYPos))
                {
                    curQuantityAndYPos.Y = Math.Min(curQuantityAndYPos.Y, bpos.Y);
                }
                else
                {
                    curQuantityAndYPos = quantityPerColumn[bposGround] = new Vec2i(0, bpos.Y);
                }

                BlockEntityFirewoodPile be = api.World.BlockAccessor.GetBlockEntity(bpos) as BlockEntityFirewoodPile;
                if (be != null)
                {
                    curQuantityAndYPos.X += be.OwnStackSize;
                }
                api.World.BlockAccessor.SetBlock(0, bpos);

                foreach (BlockFacing facing in BlockFacing.ALLFACES)
                {
                    BlockPos npos   = bpos.AddCopy(facing);
                    Block    nBlock = api.World.BlockAccessor.GetBlock(npos);

                    // Only traverse inside the firewood pile
                    if (nBlock.BlockId != firewoodBlockId)
                    {
                        continue;
                    }

                    // Only traverse within a 12x12x12 block cube
                    bool inCube = Math.Abs(npos.X - pos.X) <= maxHalfSize && Math.Abs(npos.Y - pos.Y) <= maxHalfSize && Math.Abs(npos.Z - pos.Z) <= maxHalfSize;

                    if (inCube && !visitedPositions.Contains(npos))
                    {
                        bfsQueue.Enqueue(npos);
                        visitedPositions.Add(npos);
                    }
                }
            }


            BlockPos lpos = new BlockPos();

            foreach (var val in quantityPerColumn)
            {
                lpos.Set(val.Key.X, val.Value.Y, val.Key.Z);
                int logQuantity      = val.Value.X;
                int charCoalQuantity = (int)(logQuantity * (0.125f + (float)api.World.Rand.NextDouble() / 8));

                while (charCoalQuantity > 0)
                {
                    Block charcoalBlock = api.World.GetBlock(new AssetLocation("charcoalpile-" + GameMath.Clamp(charCoalQuantity, 1, 8)));
                    api.World.BlockAccessor.SetBlock(charcoalBlock.BlockId, lpos);
                    charCoalQuantity -= 8;
                    lpos.Up();
                }
            }

            api.World.BlockAccessor.SetBlock(0, pos);
        }
예제 #6
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
        {
            if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak)
            {
                return;
            }

            BlockPos onBlockPos = blockSel.Position;
            Block    block      = byEntity.World.BlockAccessor.GetBlock(onBlockPos);

            IPlayer byPlayer = null;

            if (byEntity is EntityPlayer)
            {
                byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
            }
            if (byPlayer == null)
            {
                return;
            }


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



            if (block is BlockFirepit)
            {
                // Prevent placing firewoodpiles when trying to construct firepits
                return;
            }
            else
            {
                BlockEntity be = byEntity.World.BlockAccessor.GetBlockEntity(onBlockPos);
                if (be is BlockEntityFirewoodPile)
                {
                    BlockEntityFirewoodPile pile = (BlockEntityFirewoodPile)be;
                    if (pile.OnPlayerInteract(byPlayer))
                    {
                        handling = EnumHandHandling.PreventDefaultAction;

                        ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);
                        return;
                    }
                }

                be = byEntity.World.BlockAccessor.GetBlockEntity(onBlockPos.AddCopy(blockSel.Face));
                if (be is BlockEntityFirewoodPile)
                {
                    BlockEntityFirewoodPile pile = (BlockEntityFirewoodPile)be;
                    if (pile.OnPlayerInteract(byPlayer))
                    {
                        handling = EnumHandHandling.PreventDefaultAction;

                        ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);
                        return;
                    }
                }

                block = byEntity.World.GetBlock(new AssetLocation("firewoodpile"));
                if (block == null)
                {
                    return;
                }
                BlockPos pos = onBlockPos.Copy();
                if (byEntity.World.BlockAccessor.GetBlock(pos).Replaceable < 6000)
                {
                    pos.Add(blockSel.Face);
                }

                bool ok = ((BlockFirewoodPile)block).Construct(slot, byEntity.World, pos, byPlayer);

                Cuboidf[] collisionBoxes = byEntity.World.BlockAccessor.GetBlock(pos).GetCollisionBoxes(byEntity.World.BlockAccessor, pos);

                if (collisionBoxes != null && collisionBoxes.Length > 0 && CollisionTester.AabbIntersect(collisionBoxes[0], pos.X, pos.Y, pos.Z, byPlayer.Entity.CollisionBox, byPlayer.Entity.LocalPos.XYZ))
                {
                    byPlayer.Entity.LocalPos.Y += collisionBoxes[0].Y2 - (byPlayer.Entity.LocalPos.Y - (int)byPlayer.Entity.LocalPos.Y);
                }

                if (ok)
                {
                    handling = EnumHandHandling.PreventDefaultAction;
                    ((byEntity as EntityPlayer)?.Player as IClientPlayer)?.TriggerFpAnimation(EnumHandInteract.HeldItemInteract);
                }
            }
        }
예제 #7
0
        void ConvertPit()
        {
            Dictionary <BlockPos, Vec3i> quantityPerColumn = new Dictionary <BlockPos, Vec3i>();

            HashSet <BlockPos> visitedPositions = new HashSet <BlockPos>();
            Queue <BlockPos>   bfsQueue         = new Queue <BlockPos>();

            bfsQueue.Enqueue(Pos);

            int maxHalfSize     = 6;
            int firewoodBlockId = Api.World.GetBlock(new AssetLocation("firewoodpile")).BlockId;

            Vec3i curQuantityAndYMinMax;

            while (bfsQueue.Count > 0)
            {
                BlockPos bpos = bfsQueue.Dequeue();

                BlockPos bposGround = bpos.Copy();
                bposGround.Y = 0;

                if (quantityPerColumn.TryGetValue(bposGround, out curQuantityAndYMinMax))
                {
                    curQuantityAndYMinMax.Y = Math.Min(curQuantityAndYMinMax.Y, bpos.Y);
                    curQuantityAndYMinMax.Z = Math.Max(curQuantityAndYMinMax.Z, bpos.Y);
                }
                else
                {
                    curQuantityAndYMinMax = quantityPerColumn[bposGround] = new Vec3i(0, bpos.Y, bpos.Y);
                }

                BlockEntityFirewoodPile be = Api.World.BlockAccessor.GetBlockEntity(bpos) as BlockEntityFirewoodPile;
                if (be != null)
                {
                    curQuantityAndYMinMax.X += be.OwnStackSize;
                }

                foreach (BlockFacing facing in BlockFacing.ALLFACES)
                {
                    BlockPos npos   = bpos.AddCopy(facing);
                    Block    nBlock = Api.World.BlockAccessor.GetBlock(npos);

                    // Only traverse inside the firewood pile
                    if (nBlock.BlockId != firewoodBlockId)
                    {
                        IWorldChunk chunk = Api.World.BlockAccessor.GetChunkAtBlockPos(npos);
                        if (chunk == null)
                        {
                            return;                // Maybe at the endge of the loaded chunk, in which case return before changing any blocks and it can be converted next tick instead
                        }
                        continue;
                    }

                    // Only traverse within a 12x12x12 block cube
                    bool inCube = Math.Abs(npos.X - Pos.X) <= maxHalfSize && Math.Abs(npos.Y - Pos.Y) <= maxHalfSize && Math.Abs(npos.Z - Pos.Z) <= maxHalfSize;

                    if (inCube && !visitedPositions.Contains(npos))
                    {
                        bfsQueue.Enqueue(npos);
                        visitedPositions.Add(npos);
                    }
                }
            }

            BlockPos lpos = new BlockPos();

            foreach (var val in quantityPerColumn)
            {
                lpos.Set(val.Key.X, val.Value.Y, val.Key.Z);
                int logQuantity      = val.Value.X;
                int charCoalQuantity = (int)(logQuantity * (0.125f + (float)Api.World.Rand.NextDouble() / 8));

                int maxY = val.Value.Z;
                while (lpos.Y <= maxY)
                {
                    Block nBlock = Api.World.BlockAccessor.GetBlock(lpos);
                    if (nBlock.BlockId == firewoodBlockId)  //test for the possibility someone had contiguous firewood both above and below a soil block for example
                    {
                        if (charCoalQuantity > 0)
                        {
                            Block charcoalBlock = Api.World.GetBlock(new AssetLocation("charcoalpile-" + GameMath.Clamp(charCoalQuantity, 1, 8)));
                            Api.World.BlockAccessor.SetBlock(charcoalBlock.BlockId, lpos);
                            charCoalQuantity -= 8;
                        }
                        else
                        {
                            //Set any free blocks still in this column (y <= maxY) to air
                            Api.World.BlockAccessor.SetBlock(0, lpos);
                        }
                    }
                    lpos.Up();
                }
            }

            Api.World.BlockAccessor.SetBlock(0, Pos);
        }