Ejemplo n.º 1
0
        private bool SpillContents(IItemSlot bucketSlot, IEntityAgent byEntity, BlockSelection blockSel)
        {
            BlockPos       pos       = blockSel.Position;
            IPlayer        byPlayer  = (byEntity as EntityPlayer)?.Player;
            IBlockAccessor blockAcc  = byEntity.World.BlockAccessor;
            BlockPos       secondPos = blockSel.Position.AddCopy(blockSel.Face);


            WaterTightContainableProps props = GetContentProps(byEntity.World, bucketSlot.Itemstack);

            if (props == null || !props.AllowSpill || props.WhenSpilled == null)
            {
                return(false);
            }

            if (props.WhenSpilled.Action == WaterTightContainableProps.EnumSpilledAction.PlaceBlock)
            {
                Block waterBlock = byEntity.World.GetBlock(props.WhenSpilled.Stack.Code);

                if (props.WhenSpilled.StackByFillLevel != null)
                {
                    float         currentlitres  = GetCurrentLitres(byEntity.World, bucketSlot.Itemstack);
                    JsonItemStack fillLevelStack = null;
                    props.WhenSpilled.StackByFillLevel.TryGetValue((int)currentlitres, out fillLevelStack);
                    if (fillLevelStack != null)
                    {
                        waterBlock = byEntity.World.GetBlock(fillLevelStack.Code);
                    }
                }

                if (blockAcc.GetBlock(pos).Replaceable >= 6000)
                {
                    blockAcc.SetBlock(waterBlock.BlockId, pos);
                    blockAcc.MarkBlockDirty(pos);
                }
                else
                {
                    if (blockAcc.GetBlock(secondPos).Replaceable >= 6000)
                    {
                        blockAcc.SetBlock(waterBlock.BlockId, secondPos);
                        blockAcc.MarkBlockDirty(secondPos);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            if (props.WhenSpilled.Action == WaterTightContainableProps.EnumSpilledAction.DropContents)
            {
                props.WhenSpilled.Stack.Resolve(byEntity.World, "bucketspill");

                ItemStack stack = props.WhenSpilled.Stack.ResolvedItemstack.Clone();
                stack.StackSize = (int)(props.ItemsPerLitre * GetContent(byEntity.World, bucketSlot.Itemstack).StackSize);

                byEntity.World.SpawnItemEntity(stack, blockSel.Position.ToVec3d().Add(blockSel.HitPosition));
            }


            ItemStack emptyBucketStack = new ItemStack(this);

            if (bucketSlot.Itemstack.StackSize <= 1)
            {
                bucketSlot.Itemstack = emptyBucketStack;
                bucketSlot.MarkDirty();
            }
            else
            {
                bucketSlot.TakeOut(1);
                if (!byPlayer.InventoryManager.TryGiveItemstack(emptyBucketStack, true))
                {
                    byEntity.World.SpawnItemEntity(emptyBucketStack, byEntity.LocalPos.XYZ);
                }
            }

            byEntity.World.PlaySoundAt(props.FillSpillSound, pos.X, pos.Y, pos.Z, byPlayer);
            return(true);
        }